Women in Technology

Hear us Roar



Article:
  A Generic MVC Model in Java
Subject:   Good demonstration poor example
Date:   2004-07-19 08:42:01
From:   mbrowncpwr
The major advantage of generics is the type safety provided by the collections classes. What you demonstrated for MVC can be done more generically and with less coupling using normal inheritance and interfaces.


In the publish-subscribe (or Observer pattern), the only thing the Observable object needs to know is that the Observer implements the
update(Observable)
method. It shouldn't care if the Observer is a WidgetObserver or a WicketObserver. You actually hamper extension by placing those restrictions because now instead of iterating through a list of Observables and registering as an Observer, my Observer has to know what kind of Observable he is registering with before hand. This will probably require reflection which totally defeats both goals of inheritance and generics.

Full Threads Newest First

Showing messages 1 through 1 of 1.

  • Good demonstration poor example
    2004-07-19 09:01:16  mbrowncpwr [View]

    Actually let me correct my statement. Basically the use of generics is unecessary in the Observer pattern because as you demonstrated in your generic code, all observers have to implement the same interface either way (if they're generic or not).

    The main benefit of generics is the ability to remove typecasting away from collection classes. Now my Hashtables can know they are a collection of Widgets ordered by Strings and I can get compile time debugging when I try to put a Wicket instead of a Widget into my collection.