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

Design Pattern for a simple problem

Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Hi,

Can anyone suggest a design pattern for a simple problem.

I have two business object classes ( With setters and getters). I want to create a third class ( With setters and getters ) to be used for display. The third class will contain data extracted from the first two.

I have usually implemented this by having a static utility method that reads of the two objects and creates the third.

Would there be a pattern that could be put in use here.

Thanks


Mahesh Trikannad
Atulya Mahajan
Greenhorn

Joined: Dec 16, 2007
Posts: 14
Not very clear about what you are going to do with the data in the two classes (a,b).
Is the third class(c) going to copy the data into itself, or can it just use getter methods of a and b to do its thing?

Possibly, you could do a facade pattern using a and b to provide the functionality of c?
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
C has some kind of aggregation of A and B ,but is a standalone class with getters and setters. Assume that the viewer can only deal with C and cannot deal with A and B.

So the functionality is to extract data from A and B to create C.
Atulya Mahajan
Greenhorn

Joined: Dec 16, 2007
Posts: 14
To me, facade sounds about right.

C contains objects of A and B.
Users invoke methods of C, which in turn invoke methods of A and B to do whatever it is that they have to do.

My two cents. What do the experts say?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Sounds about right.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mahesh Trikannad
Ranch Hand

Joined: Dec 14, 2004
Posts: 68
Let me add a little more detail to the problem. Note it is a simple problem. Just trying to gauge if I can user a better design.

First of c cannot contain just a and b. So lets say a contains cola1,cola2 and a list of b. and b contains colb1,colb2

So c needs to contain and display cola1,cola2,colb1,colb2. Note that contents of cola1 and cola2 may get repeated. So the display gets a list of c.

A pattern iam looking for is for the creation of c. As of now I have a utility class which does the needfull ( Read from a, iterate on b, etc ).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design Pattern for a simple problem