Sunday, August 14, 2016

Prototype Pattern

Clone - Create new objects from the existing instance of the object. It does not affect the original object when any changes.

Shadow Clone - Only Self Class was cloned. (Child Class No Clone)
Deep Clone - Self and Child Class was cloned.


public Customer GetClone()
{
     Customer customer;
     customer = (Customer)this.MemberwiseClone();
     customer.address = (Address)address.GetClone();

     return customer;
}

public Address GetClone()
{
     Address address;
     address = (Address)this.MemberwiseClone();

     return address;
 }

Customer customerB = null;

customerB = customerA.GetClone();

No comments:

Post a Comment