Question of the day :Day2




Question of the day.


Well its the second day ,The growing fi eld of Design Patterns offers hope of controlling the complexities associated with the development of large software applications.Making things simpler makes a lot of sense.So today’s question is related to design patterns

Question:
How could you ensure that only a single instance of a given object can exist?

Answer:
The answer is to make the class a Singleton, which ensures that only a single instance of the class can exist.

How this is done?

  • Declaring class as sealed
  • Defining a private constructor to prevent outside object initialization
  • HappyCoding ! 😉

    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

    %d bloggers like this: