Inheritance



  • We have some objects that descend from 2 completely non-intersecting hierarchies:

     

       public class Event_1 extends DeepHierarchyA { }
    public class Event_2 extends DeepHierarchyB { }


    A need comes up for a new entity that is a logical extension of Event_1, but needs to be processed like Event_2. As such, the solution they came up with is:


       public class Event_3 extends Event_1 { }
    public class Event_4 extends Event_2 {
    private Event_3 e3;
    // Expose every method of Event_2 as a wrapper that
    // delgates manual massaging of Event_1 and Event_3
    }

    So now, List<Event_2> contains both Event_2 and Event_4 (really Event_3).

    Personally, I would have just extended Event_2 to accomplish the same thing.

    What they did do seems like a total WTF, at least to me.

    Thoughts?

     



  • You clearly need to hit them with the Gang of Four's [url=http://en.wikipedia.org/wiki/Design_Patterns]book[/url].



  • Ah, the old beaglepuss design pattern.

    (Or Guy Fawkes if you prefer.)



  • Considering Guy Fawkes day is coming up I'll go with that one.

    As for a class that needs to derive from two separate classes, without working with the GOF patterns my first thought would be to create one that interns both, essentially an empty class that contains the two instead of inheriting from one and interning another.

    Essentially some form of Facade, oops, there's GOF leaking out.



  • It's probably too late to say something like "interface", right?



  • @powerlord said:

    You clearly need to hit them with the Gang of Four's book.

     so they can start calling all their classes Visitor and their methods accept() and visit()

     

     


Log in to reply