• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Patterns

 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One point... The default constructor of a singleton instance should be private. You can also use Enums for singleton




/Danjel

 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry that is what I meant, private not public, my mind is going, being crammed with information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic