Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes OO, Patterns, UML and Refactoring and the fly likes What pattern should be used for making factory of Services? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "What pattern should be used for making factory of Services?" Watch "What pattern should be used for making factory of Services?" New topic
Author

What pattern should be used for making factory of Services?

Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 369
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




Regards
Azrael Noor
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 292
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

Joined: Jul 29, 2012
Posts: 292
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

Joined: Jul 29, 2012
Posts: 292
Here is a reference about Type Object pattern:http://www.cs.sjsu.edu/~pearce/modules/patterns/analysis/top.htm
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What pattern should be used for making factory of Services?
 
Similar Threads
CXF Dynamic WS Client
web of knowledge
Invoke .NET Web Service using Java/Axis passing SoapHeader
ServiceFactory.newInstance
Web service + xml + java