File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Design query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Design query" Watch "Design query" New topic
Author

Design query

Preeti Prabhakar
Greenhorn

Joined: Jul 27, 2009
Posts: 12
Hi All,

I have a scenario as given below for 3 different consumers.

public ObjA createData(){}
public ObjB createData(){}
public ObjC createData(){}

The objects ObjA, ObjB and ObjC are wrappers around some specific object but are created differently as per the specific requirements of the consumer.
We have a designed a interface having createData() with return type as Map and we are trying to interpret the returned object based on the consumer request. Is there a flaw in this design (having return type as Map and then extracting the required value) ?

Please advise.

Thanks,
Preeti
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Based on what you stated, you are asking about the method declaration below:



And the Map instance will only have a single object in it. Will client objects all use a single key to extract the object from the Map?

You don't really need a Map to hold a single object. What about?

Preeti Prabhakar
Greenhorn

Joined: Jul 27, 2009
Posts: 12
Thanks Jimmy for the reply.



The above code snippet should be good enough. But does this design have a drawback ? I have one apprehension - the actual instance of the parameter that is returned by createData() will be
known only at runtime. Compile time errors wont be caught. Is this a bad design ?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Do you plan on writing code with errors?

How do you prevent errors with the following?



...the actual instance of the parameter that is returned by createData() will be known only at runtime.


Are you writing the code that will create the instance at runtime?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Design query
 
Similar Threads
Comparator interface
SCEA 5 / 1 - JPA question
Garbage collection
Island of Isolation
HashMap with unique key & unique values