ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
เขียนโปรแกรมบน iPhone ด้วย MonoTouch
News
Php Tips
Ubuntu
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
C# Design Pattern
Linux Quick Tips
C# Tips & Technique
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
MAVEN
Database & SQL
ZengCode Framework Guide
Mac OSx
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Prototype Pattern  (2010-03-15)

Protype pattern is a pattern for produce new objects from a instance, of the same class, basically clonning objects.
For implement prototype pattern in c#, class must implement ICloneable interface ขออนุญาติไม่แปรนะครับ กัวจะแปลแล้วเข้าใจยากหนักกว่าเดิม

 namespace Prototype
{

public class MyPrototype : ICloneable
{
  public String myName;

  public MyPrototype(String myName)
  {
    this.myName = myName;
  }

  public object Clone()
  {
    MyPrototype newObj = new MyPrototype(this.myName);
    newObj.myName = this.myName;
    return newObj;
  }

}//class
}//Prototype

 การเรียกใช้นะครับ

 

 
            MyPrototype obj1 = new MyPrototype("Chiwa Kantawong");

            MyPrototype obj2 = (MyPrototype) obj1.Clone();

            MessageBox.Show(obj1.myName + " <===> " + obj2.myName);

 


Comment
Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.197703 seconds to load.