Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Pattern for a simple problem

 
Mahesh Trikannad
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Atulya Mahajan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds about right.
 
Mahesh Trikannad
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic