Results 1 to 3 of 3
  1. #1
    hencre is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Java Design Problem


    Current Design-->
    BaseManager extends Manager extends Type1DataStoreImpl implements DataStoreInterface
    BaseManager is referenced everywhere like
    for (DataStoreInterface o:BaseManager.getAllObjects()){};

    I have Type2DataStoreImpl implements DataStoreInterface

    I want to make minimum changes to the application ie BaseManager & Manager should not be replaced by new classes.
    Is there a way I can dynamically plug Type2DataStoreImpl as parent of Manager ( .properties file decides its type1 or type2 implementation) ?

    New Design
    BaseManager extends Manager extends Type1DataStoreImpl or Type2DataStoreImpl (depending on config file) implements DataStoreInterface

    Thanks in advance.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Knowing only what you said about your design, I think your problem is that Manager is not *a* DataStoreInterface. Instead, Manager *uses* a DataStoreInterface. The DataStoreInterface implementation used depends on the config file.

    At least, I see a lot of code posted on the forum that makes this mistake. One class is trying to be several different things. Instead, several classes should be one thing each and work together.

    Look at your Manager design. Conceptually, can you add an instance field of type DataStoreInterface? If so, modify your manager class to access the methods of the instance field.

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    Steve is spot on here. This is why "has-a" is generally preferred over "is-a", and why "implements" is preferred over "extends".

    I seriously doubt that a Manager conceptually is a Type1DataStoreImpl. Someone was lazy and you are paying the price.

Similar Threads

  1. Java Mashup API - Design Patterns Questionnaire
    By goldeneyeone in forum Reviews / Advertising
    Replies: 0
    Last Post: 02-10-2009, 11:03 PM
  2. overall design of a java application
    By willemjav in forum New To Java
    Replies: 2
    Last Post: 08-20-2008, 12:37 AM
  3. A few questions about Java and design
    By ldb88 in forum New To Java
    Replies: 4
    Last Post: 12-07-2007, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts