Lecture overview -- Keyboard shortcut: 'u'  Previous page: Cloning -- Keyboard shortcut: 'p'  Next page: The fragile base class problem -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 31 : 37
Object-oriented Programming in C#
Abstract classes, Interfaces, and Patterns
Cloning in C#

Internally, C# supports shallow cloning of every object.

Externally, it must be decided on a class-by-class basis if cloning is supported.

 

  • Cloning in C#

    • Shallow cloning is facilitated by the protected method MemberwiseClone in System.Object

    • A class C that allows clients to clone instances of C should implement the interface ICloneable

/user/normark/oop-csharp-1/sources/c-sharp/interfaces/reproductions/ICloneable.csA reproduction of the interface ICloneable.


/user/normark/oop-csharp-1/sources/c-sharp/point/cloneable/Point.csA cloneable class Point.


/user/normark/oop-csharp-1/sources/c-sharp/point/cloneable/Client.csA sample client of class Point.


/user/normark/oop-csharp-1/sources/c-sharp/point/cloneable/Client-in-error.csIllegal cloning with MemberwiseClone.