wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Design Patterns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Design Patterns" Watch "Design Patterns" New topic
Author

Design Patterns

Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
Hi All,

So I am currently studying for the OCPJP exam and have come across the sections requiring you to learn about:

Singleton
DAO Pattern
Factories and using factories from the API
Object Composition

Well from some googling this is what I understand so far:

Singleton:
to create only one instance of the class for the specific purpose, to do this:
set the default constructor as private
provide a public method to create and instance if one hasn't been created already
store the object in a private reference variable
to be 100% sure no one else can create a second object override the clone() method and throw a CloneNotSupportedException
It is suggested to mark the method synchronized

DAO Pattern:
Data Access Object - DAO
An object that provides an abstract interface to some type of database or persistence mechanism, providing specific operations without exposing details about the database.
the advantage is the relatively simple and rigorous separation between two parts of an application that can and should know very little of each other.

Factory
An object for creating other objects.
Typically has a method for every kind of object it is capable of creating.
determines the actual type of object to be created.

Object Composition
a way to combine simple objects into more complex ones. eg a car object is made up of objects like, an engine, wheels etc.
So a car has-a engine and a car has-a wheel etc.

So what I want to know is what I found correct in terms of Java technology?
And can you refer me to more comprehensive explanations and if possible examples?
Also do you know of any tutuorials or examples one could play with these ideas with?

And yes I plan to read head first Design patterns but am not quite there yet.

Regards,
Wes

Danjel Nyberg
Greenhorn

Joined: Sep 12, 2012
Posts: 15

One point... The default constructor of a singleton instance should be private. You can also use Enums for singleton




/Danjel

Wesleigh Pieters
Ranch Hand

Joined: Sep 04, 2012
Posts: 81
sorry that is what I meant, private not public, my mind is going, being crammed with information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design Patterns
 
Similar Threads
abstract and abstract factory
Purpose of hiding default constructor
composition and aggregation
Questions regarding the DAO pattern
a bunch of questions