• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What pattern should be used for making factory of Services?

 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a case like


QualifiedPortName, QualifiedServiceName are dynamic, values changes for particular SERVICEType.

I wanted to make a class which returns objWSContext.getPort(QualifiedPortName,ServiceType3PortTypeV03.class) object back.

Which pattern is best as sometimes i have to do this



 
Himai Minh
Ranch Hand
Posts: 1329
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe, try abstract factory pattern, just like Calendar class in Java API. When you create an instance of a ServiceType, do this:
ServiceType service = ServiceType.getInstance()
You may want to create a class called ServiceType and extend it with subtype.

Another pattern I can think of is type object pattern developed by Ralph Johnson and Bobby Woolf. You can google it.
The general idea is to create a ServiceType class and associate some classes to this ServiceType.
For example, there is a Movie class that has a reference to MovieType class. You don't need to create Movie class extending it to ClassicalMovie, MusicalMovie, DocumentaryMovie.... Your MovieType class has attributes that describe what type it is.
When you create a new Movie object, you don't need to worry about what Movie type it is. You just need to do Movie m = new Movie("MusicalMovie"); instead of Movie m = new MusicalMovie(); and etc.
So, if the Movie has a "MusicalMovie" string attribute, refer a MusicalMovie object to it and etc.

This is just my general idea. Hope this help.
 
Himai Minh
Ranch Hand
Posts: 1329
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to try Bridge Pattern.
You have ServiceType (and possibly its subtype). You also create a class called Service. Your ServiceType object associates with a Service object and invoke Service's moethods.
For example,

ServiceType serviceType = new ServiceType1();

serviceType.operate();


What is the implemenation details of operate()?


 
Himai Minh
Ranch Hand
Posts: 1329
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a reference about Type Object pattern:http://www.cs.sjsu.edu/~pearce/modules/patterns/analysis/top.htm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic