Class-Creation Patterns: Object-Creational Patterns
Class-Creation Patterns: Object-Creational Patterns
Object Pool:
Avoid expensive acquisition and release of resources by recycling
objects that are no longer in use
Example:
You have a test for job For the preparation of test you need books. You
will borrow books from the library, and after the test you will return those
books to the library.Library uses those books to serve other people. Here,
the books are the objects. The books are getting reused. Instead of
buying the books we are trying to get books from the library. After the
books are returned, the library representative will reuse those books. The
library representative will serve many people.
Prototype
A fully initialized instance to be copied or cloned.
Example:
Company creates a new product. Later they decided to create a new
product pro. It is a good idea to build everything from scratch or just
reiterate the existing design of product and reuse it? As you see by reuse
existing objects we are saving resources and time.he Prototype Design
Pattern is the same approach in software engineering.
Singleton
A class of which only a single instance can exist
Example:
A head of a school,he is one incharge. He is responsible for important
decisions and requests are directed to him because of responsibility.