aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes What design pattern is this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "What design pattern is this?" Watch "What design pattern is this?" New topic
Author

What design pattern is this?

Kenny Johnson
Ranch Hand

Joined: Jan 01, 2007
Posts: 37
A common theme I am seeing for implementing the SCJD assignment is the 3 tier approach:

Layer 1: DB interface ( provided by sun ) and then a Data class which implements these methods. Provides actual I/O to the database.

Layer 2: A business layer of sorts. An abstract class called something like DataBaseService defines read/write/update methods that delegate to the Data class. Then sub classes are created which are tailored to either a local or remote approach. So you would have say, LocalDataBaseService and RemoteDataBaseService. A Factory would be created to return the appropriate implementation in your view layer. The client ( the view code ) would never know if its using the Local or Remote version. It just knows its using a DataBaseService.

Layer 3: The GUI layer. For the SCJD it is in SWING, but could be in HTML or some other GUI technology. The view would use the Factory mentioned in the previous paragraph to instantiate an instance of DataBaseService. The "action listeners" or some other event processor would fire methods in DataBaseService to perform database operations. The DataBaseService could possibly implement Observable, so that GUI clients could implement Observer ( and add the instance of DataBaseService to its observables list ) and update the GUI when notifications are passed along.

is this design considered MVC or some other pattern? It looks like layer 1 could be the model, layer 2 the controller, and layer 3 the view.... or am I mistaken? A friend of mine says this is not MVC. He says all it is is the Adapter pattern ( layer 2 ). He said Layer 1 and 2 are not much different from each other- and are not clear model and controller layers.
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

Kenny Johnson wrote:is this design considered MVC or some other pattern? It looks like layer 1 could be the model, layer 2 the controller, and layer 3 the view.... or am I mistaken?

Depending on the details of implementation, the three layers you describe could be considered either an example of Model-View-Controller or an example of Model-Delegate. It would be normal for the business layer and data access layer to comprise the model, but this can be achieved with different degrees of entanglement and different loci of control.

A friend of mine says this is not MVC. He says all it is is the Adapter pattern ( layer 2 ). He said Layer 1 and 2 are not much different from each other- and are not clear model and controller layers.

The Adapter pattern allows one object to consume the services of an incompatible provider through a mediator object that provides the API the consumer expects and then translating that (byfm) into API calls on the provider.

In a strict sense, your friend is mistaken; he's applying to an entire application architecture the label that fits properly only on the reconciliation of two incompatible classes.

On the other hand, your friend is right that there's an adapter-like character to the C in the MVC pattern. It reconciles the expectations of the presentation layer to the provisions of the service layer.

But this is trivially true of all programming that achieves loose coupling via interfaces and separation of concerns. All non-brittle software consists, in some broad and perhaps metaphorical sense, of adapters that serve as Babel-fish in the ears of otherwise discrete agents.


OCMJD 6, OCPJP7, Baroque Potion, G+
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What design pattern is this?