subclass

How do I use AutoMapper to map multiple subclasses into one class?

本小妞迷上赌 提交于 2019-12-18 15:09:35
问题 Let's assume I have three classes that are subclasses of a base class: public class BaseClass { public string BaseName { get; set; } } public class Subclass1 : BaseClass { public string SubName1 { get; set; } } public class Subclass2 : BaseClass { public string SubName2 { get; set; } } public class Subclass3 : BaseClass { public string SubName3 { get; set; } } I would like to map these to a ViewModel class that looks like this: public class ViewModel { public string BaseName { get; set; }

Java — Initializing superclass variables in subclasses?

喜你入骨 提交于 2019-12-18 05:56:26
问题 Okay, so, for example, let's say I have an abstract class called "Vehicle". The Vehicle class, has, among other things, a static variable called wheels, which is not initialized. What I want to do is have other subclasses extending from the Vehicle class, like "Motorcycle", and "Truck", and in these subclasses, have the wheels initialized. Code: public abstract class Vehicle { static int wheels; //number of wheels on the vehicle } But the below doesn't work: public class Motorcycle extends

Subclassing DropDownList in ASP.NET

流过昼夜 提交于 2019-12-18 05:02:26
问题 I want to subclass the built-in DropDownList in ASP.NET so that I can add functionality to it and use it in my pages. I tried doing this with a UserControl but found that it doesn't expose the internal DropDownList (logically, I guess). I've googled for the answer but can't find anything. I've come as far as writing the actual class, and it's possible to subclass from DropDownList but I'm unable to register the file in my ASP.NET page and use it in the source view. Maybe I'm missing some

Subclassing NSView to have a transparent background

♀尐吖头ヾ 提交于 2019-12-18 04:45:07
问题 I am creating an app where I need to have a transparent NSView with a transparent PNG image inside. The problem is, the NSView I'm drawing has a gray background on it. I have it subclassed (as TransparentRectangleView) but don't know what to put in drawRect to make it transparent. I have already overridden the isOpaque method to return NO but it doesn't seem to help... Alternatively, is there already a subclassed NSView that is similar to the iPhone's UIImageView (as long as I can add

C++ friend inheritance?

走远了吗. 提交于 2019-12-18 01:27:47
问题 Does a subclass inherit, the main class' friend associations (both the main class' own and other classes friended with the main class)? Or to put it differently, how does inheritance apply to the friend keyword? To expand: And if not, is there any way to inherit friendship? I have followed Jon's suggestion to post up the design problem: C++ class design questions 回答1: Friendship is not inherited in C++. The standard says (ISO/IEC 14882:2003, section 11.4.8): Friendship is neither inherited

When to use categories and when to use subclassing? [closed]

大城市里の小女人 提交于 2019-12-17 21:58:08
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Can anybody tell me when to use categories and when to use subclassing in Objective-C? Also please tell me the advantages and disadvantages of them. 回答1: An objective-c category is useful if you want to alter the behavior of ALL instances of the class, with minimal code.

Is subclassing in Objective-C a bad practice?

房东的猫 提交于 2019-12-17 21:56:43
问题 After reading lots of blogs, forum entries and several Apple docs, I still don't know whether extensive subclassing in Objective-C is a wise thing to do or not . Take for example the following case: Say I'm developing a puzzle game which has a lot of elements. All of those elements share a certain amount of the same behaviour. Then, within my collection of elements, different groups of elements share equal behaviour, distinguishing groups from groups, etc... So, after determining what

Disallow subclasses from overriding Java method

浪尽此生 提交于 2019-12-17 19:18:06
问题 Suppose I have a method in a Java class, and I don't want any subclass of that class to be able to override that method. Can I do that? 回答1: You can declare the method to be final , as in: public final String getId() { ... } For more info, see http://docs.oracle.com/javase/tutorial/java/IandI/final.html 回答2: Simply make the method final . 回答3: If your method is not part of your builded API and isn't directly called by subclasses, prefer simply making your method private . If your class

Returning an objects subclass with generics

别来无恙 提交于 2019-12-17 18:42:18
问题 With an abstract class I want to define a method that returns "this" for the subclasses: public abstract class Foo { ... public <T extends Foo> T eat(String eatCake) { ... return this; } } public class CakeEater extends Foo {} I want to be able to do things like: CakeEater phil = new CakeEater(); phil.eat("wacky cake").eat("chocolate cake").eat("banana bread"); Arguably banana bread would throw an IllegalArgumentException with the message "Not a cake!" 回答1: public abstract class Foo<T extends

iOS: UIView subclass init or initWithFrame:?

泪湿孤枕 提交于 2019-12-17 17:28:58
问题 I made a subclass of UIView that has a fixed frame. So, can I just override init instead of initWithFrame: ? E.g.: - (id)init { if ((self = [super initWithFrame:[[UIScreen mainScreen] bounds]])) { self.backgroundColor = [UIColor clearColor]; } return self; } The Xcode documentation for -initWithFrame: says: "If you create a view object programmatically, this method is the designated initializer for the UIView class. Subclasses can override this method to perform any custom initialization but