wood burning stoves 2.0*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
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: 378
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: 600
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: 600
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: 600
Here is a reference about Type Object pattern:http://www.cs.sjsu.edu/~pearce/modules/patterns/analysis/top.htm
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What pattern should be used for making factory of Services?
 
Similar Threads
Invoke .NET Web Service using Java/Axis passing SoapHeader
CXF Dynamic WS Client
web of knowledge
Web service + xml + java
ServiceFactory.newInstance