• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Design Patterns

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 15
MS IE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry that is what I meant, private not public, my mind is going, being crammed with information.
 
This tiny ad is wafer thin:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic