/// <summary> /// Creates a new <see cref="GeometricObject"/> that is a clone (deep copy) of the current /// instance. /// </summary> /// <returns> /// A new <see cref="GeometricObject"/> that is a clone (deep copy) of the current instance. /// </returns> /// <remarks> /// <strong>Notes to Inheritors:</strong> The method <see cref="Clone"/> calls /// <see cref="CreateInstanceCore"/> which is responsible for creating a new instance of the /// <see cref="GeometricObject"/> derived class and <see cref="CloneCore"/> to create a copy of /// the current instance. Classes that derive from <see cref="GeometricObject"/> need to /// implement <see cref="CreateInstanceCore"/> and <see cref="CloneCore"/>. /// </remarks> public GeometricObject Clone() { GeometricObject clone = CreateInstance(); clone.CloneCore(this); return(clone); }
private GeometricObject CreateInstance() { GeometricObject newInstance = CreateInstanceCore(); if (GetType() != newInstance.GetType()) { string message = String.Format( CultureInfo.InvariantCulture, "Cannot clone geometric object. The derived class {0} does not implement CreateInstanceCore().", GetType()); throw new InvalidOperationException(message); } return(newInstance); }
protected virtual void CloneCore(GeometricObject source) { Pose = source.Pose; Shape = source.Shape.Clone(); Scale = source.Scale; }