Tuesday, February 19, 2013

Some  creational design patterns not mentioned in designpatterns book:

   1)Multiton - As similar to singleton, different objects with single instance . I am having one car and one bike.this is multiton.
    if I am having only instance of bike,singleton comes to picture.
   2)Object pool - to improve performance and avoid runtime creation/deletion of objects by allocating pool of objects
                 - This will avoid memory fragments
       Example:
            1)balls in Snow bowling
                [3 or 6 balls are gathered at a time before   playing it]
            2)RingBuffer- Allocates predefined buffer or frame sizes and reuse
               it without deleting and creating it at runtime

  3)Resource Acquisition Is Initialization [RAAI]            - whenever we forget to release the memory pointer or mutex locks,this can be used
                - Writing a class around the pointers to allocate memory/acquire mutex lock on constructor and release the memory pointer or release the mutex lock in destructor.
            -if we are using this class, it will be stored in object. whenever client fn is using it,it will be stored in stack. whenver function goes out of stack, it will automatically deallocate or release the resources. client fn doesnt need to take care of releasing resources on every failure and success return cases.

   4) Lazy initialization           - Delaying of memory allocation at runtime whenever the user is requesting,that time only resources will be allocated in memory

Labels:

0 Comments:

Post a Comment

<< Home