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

    Default Java Design Problem

    hi,

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

    Modification-->
    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
    Posts
    1,046
    Rep Power
    7

    Default

    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
    Posts
    671
    Rep Power
    6

    Default

    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, 10:03 PM
  2. overall design of a java application
    By willemjav in forum New To Java
    Replies: 2
    Last Post: 08-19-2008, 11:37 PM
  3. A few questions about Java and design
    By ldb88 in forum New To Java
    Replies: 4
    Last Post: 12-07-2007, 12: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
  •