inheritance

Is Interface inheritance a bad practice?

假装没事ソ 提交于 2020-01-01 04:45:36
问题 I was wondering if the following code shows a bad practice (about interface inheritance): public interface IFoo : IDisposable { void Test(); } public class TestImpl : IFoo { public void Test() { // do something } public void Dispose() { // disposing my dependencies } } public class FooFactory { public IFoo CreateFoo() { return new TestImpl(); } } public class Client { public void Main() { FooFactory factory = new FooFactory(); using(IFoo foo = factory.CreateFoo()) { // do stuff then auto

C# Generics - How do I return a specific type?

不问归期 提交于 2020-01-01 04:34:09
问题 Maybe I'm going about this all wrong. I have a bunch of classes that derive from the "Model" class, a base class with a bunch of common properties and methods. I want them all to implement a set of functionality: public abstract void Create(); public abstract T Read<T>(Guid ID); //<--Focus on this one public abstract void Update(); public abstract void Delete(); Then I implement it in a child class like "Appointment" like so: public override T Read<T>(Guid ID) { var appt = db.Appointments

Is packaging type 'pom' needed when not using project aggregation (multimodule)?

二次信任 提交于 2020-01-01 04:31:07
问题 I want to inherit the dependencies of a (parent) pom.xml in a child project in Maven 2.2.1; i.e. use project inheritance. It seems it is necessary to change the default packaging type from jar to pom in this case. However, doesn't the Maven2 documentation state that the packaging type pom is necessary for project aggregation, i.e. multimodule projects which use submodules, but not for project inheritance? <project> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId

How can I get all the inherited classes of a base class? [duplicate]

↘锁芯ラ 提交于 2020-01-01 04:30:06
问题 This question already has answers here : How to find all the types in an Assembly that Inherit from a Specific Type C# (4 answers) Get all derived types of a type (8 answers) Closed 6 years ago . class Foo { } class Foo1 : Foo { } class Foo2 : Foo { } How would I be able to get all the classes that use Foo as a base class? The inherited classes aren't necessary in the same assembly. 回答1: This is not fast, but as long as Foo is a concrete type (not an interface), then it should work. Foo

How to Inherit A Model from Another Model in CodeIgniter

你离开我真会死。 提交于 2020-01-01 04:27:05
问题 i'm using codeigniter for my project and i have this class model which i call Genesis which looks like this: class Genesis_model extends CI_Model { function __construct() { parent::__construct(); } function get() { return 'human soul'; } } and i have another model, stored in the same directory, which extends Genesis_model class Human_model extends Genesis_model { function __construct() { parent::__construct(); } function get_human() { return $this->get(); } } Human_model is used by Human

Doctrine table class inheritance when one subclass has no extra attributes

让人想犯罪 __ 提交于 2020-01-01 04:20:06
问题 I'm having a problem with my mapping. I can't get it to work. I have an abstract base class like so: /** * @Entity * @Table(name="actions") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="type", type="string") * @DiscriminatorMap({"FOO" = "FooAction", "BAR" = "BarAction", ...}) */ abstract class AbstractAction { ... } I have a bunch of different actions, all with different fields. E.g: /** * @Entity * @Table(name="actions_foo") */ class FooAction extends AbstractAction { ... } But

Is there a convention for showing overridden methods in UML static class diagrams?

a 夏天 提交于 2020-01-01 04:11:05
问题 If class Human inherits some methods from superclass Mammal unchanged (such as laysEggs: () -> false ) and overrides other methods (such as postsToStackOverflow : () -> true ), is there any difference between how the different methods are indicated in portion of the UML static class diagram for Human ? For example, are only the overridden methods shown in the box for Human , or are both shown, with some annotation for the overridden methods? 回答1: Now there is. Some anonymous got me to dig

c++ multiple inheritance casting

风流意气都作罢 提交于 2020-01-01 04:09:26
问题 I have a class: class Base; Also I have an interface class Interface; Next i'm creating a class class Derived : public Base, public Interface; If I have Base *object = new Derived; How can i cast object to Interface ? (of course if i know than object is actually a derived class) EDIT: I've tried dynamic_cast and static_cast (not compiled). So let me explain the problem a bit more: I have: class Object {...} class ITouchResponder { public: virtual bool onTouchBegan(XTouch *touch) = 0; virtual

avoid instanceof in Java

假如想象 提交于 2020-01-01 04:05:09
问题 I have been told at some stage at university (and have subsequently read in upteen places) that using instanceof should only be used as a 'last resort'. With this in mind, is anyone able to tell be if the following code I have is a last resort. I have had a look around on stack overflow but cannot quite find a similar scenario - perhaps I have missed it? private void allocateUITweenManager() { for(GameObject go:mGameObjects){ if (go instanceof GameGroup) ((GameGroup) go).setUITweenManager

C++ vs Java constructors

半世苍凉 提交于 2020-01-01 03:28:49
问题 According to John C. Mitchell - Concepts in programming languages, [...] Java guarantees that a constructor is called whenever an object is created. [...] This is pointed as a Java peculiarity which makes it different from C++ in its behaviour. So I must argue that C++ in some cases does not call any constructor for a class even if an object for that class is created. I think that this happens when inheritance occurs, but I cannot figure out an example for that case. Do you know any example?