class-hierarchy

Is there any reason for an empty concrete method in an abstract class?

非 Y 不嫁゛ 提交于 2019-11-30 05:40:52
问题 I was recently looking through some open source code PicketLink code. If you take a look at this class, you'll see a number of concrete methods in an abstract class that do nothing. Is there any purpose whatsoever for this? I thought about two things: If the method needs to be overriden by subclasses and not defined in the parent abstract class, why not simply make it abstract? If only some of the child classes actually need to implement the method, wouldn't this indicate the need for a

I need to implement C# deep copy constructors with inheritance. What patterns are there to choose from?

纵饮孤独 提交于 2019-11-30 05:02:37
I wish to implement a deepcopy of my classes hierarchy in C# public Class ParentObj : ICloneable { protected int myA; public virtual Object Clone () { ParentObj newObj = new ParentObj(); newObj.myA = theObj.MyA; return newObj; } } public Class ChildObj : ParentObj { protected int myB; public override Object Clone ( ) { Parent newObj = this.base.Clone(); newObj.myB = theObj.MyB; return newObj; } } This will not work as when Cloning the Child only a parent is new-ed. In my code some classes have large hierarchies. What is the recommended way of doing this? Cloning everything at each level

Is there any relation between the class that implements interface and that interface?

孤人 提交于 2019-11-29 11:08:20
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there is a relationship between a subclass and its superclass (is-a). Q: Is there any relationship like "is-a" between Book and Taxable ? GOOD Answers, but you said that "is-a" is also a relationship between Book and Taxable , but "is-a" is a relation between classes , and an interface is not a class! Yes. The relationship is exactly the same Book is a Taxable too. EDIT An interface is an artifact that happens to match Java's ( and probably C# I don't know ) interface keyword. In OO interface is the set of

I need to implement C# deep copy constructors with inheritance. What patterns are there to choose from?

一曲冷凌霜 提交于 2019-11-29 03:17:21
问题 I wish to implement a deepcopy of my classes hierarchy in C# public Class ParentObj : ICloneable { protected int myA; public virtual Object Clone () { ParentObj newObj = new ParentObj(); newObj.myA = theObj.MyA; return newObj; } } public Class ChildObj : ParentObj { protected int myB; public override Object Clone ( ) { Parent newObj = this.base.Clone(); newObj.myB = theObj.MyB; return newObj; } } This will not work as when Cloning the Child only a parent is new-ed. In my code some classes

Application to generate Java class hierarchy diagram [closed]

瘦欲@ 提交于 2019-11-28 21:58:09
Looking for a tool that: Produces a visually pleasing (not garish), orthogonally structured graph hierarchy Outputs high-quality PNG images (300dpi+) Visually differentiates classes, abstract classes, interfaces, and enumerated types (preferably by colour) Interactive user interface Allows pruning of packages and/or individual classes from the diagram Seeds (e.g., File » Open ) using a set of: Directories JAR files Individual source files Individual compiled classes Performs a fully automatic analysis of class dependencies Searches classpath to resolve as many unmet dependencies as possible

Table design and class hierarchies

孤人 提交于 2019-11-28 01:39:11
Hopefully someone can shed some light on this issue through either an example, or perhaps some suggested reading. I'm wondering what is the best design approach for modeling tables after their class hierarchy equivalencies . This can best be described through an example: abstract class Card{ private $_name = ''; private $_text = ''; } class MtgCard extends Card{ private $_manaCost = ''; private $_power = 0; private $_toughness = 0; private $_loyalty = 0; } class PokemonCard extends Card{ private $_energyType = ''; private $_hp = 0; private $_retreatCost = 0; } Now, when modeling tables to

NHibernate - Changing sub-types

早过忘川 提交于 2019-11-28 00:14:52
How do you go about changing the subtype of a row in NHibernate? For example if I have a Customer entity and a subclass of TierOneCustomer, I have a case where I need to change a Customer to a TierOneCustomer but the TierOneCustomer should have the same Id (PK) as the original Customer entity. The mapping looks something like this: <class name="Customer" table="SiteCustomer" discriminator-value="C"> <id name="Id" column="Id" type="Int64"> <generator class="identity" /> </id> <discriminator column="CustomerType" /> ... properties snipped ... <subclass name="TierOneCustomer" discriminator-value=

Force all classes to implement / override a 'pure virtual' method in multi-level inheritance hierarchy

我是研究僧i 提交于 2019-11-27 09:10:06
In C++ why the pure virtual method mandates its compulsory overriding only to its immediate children (for object creation), but not to the grand children and so on ? struct B { virtual void foo () = 0; }; struct D : B { virtual void foo () { ... }; }; struct DD : D { // ok! ... if 'B::foo' is not overridden; it will use 'D::foo' implicitly }; I don't see any big deal in leaving this feature out. For example, at language design point of view, it could have been possible that, struct DD is allowed to use D::foo only if it has some explicit statement like using D::foo; . Otherwise it has to

How to test if one java class extends another at runtime?

↘锁芯ラ 提交于 2019-11-27 00:00:55
How to I test if a is a subclass of b ? Class<?> a = A.class; Class<?> b = B.class; Are you looking for: Super.class.isAssignableFrom(Sub.class) Rob Hruska If you want to know whether or not a Class extends another, use Class#isAssignableFrom(Class) . For your example, it would be: if(B.class.isAssignableFrom(A.class)) { ... } If you're interested in whether or not an instance is of a particular type, use instanceof : A obj = new A(); if(obj instanceof B) { ... } Note that these will return true if the class/instance is a member of the type hierarchy and are not restrictive to direct

Force all classes to implement / override a &#39;pure virtual&#39; method in multi-level inheritance hierarchy

自闭症网瘾萝莉.ら 提交于 2019-11-26 14:33:57
问题 In C++ why the pure virtual method mandates its compulsory overriding only to its immediate children (for object creation), but not to the grand children and so on ? struct B { virtual void foo () = 0; }; struct D : B { virtual void foo () { ... }; }; struct DD : D { // ok! ... if 'B::foo' is not overridden; it will use 'D::foo' implicitly }; I don't see any big deal in leaving this feature out. For example, at language design point of view, it could have been possible that, struct DD is