Каков правильный способ реализации ICloneable
в иерархии классов? Скажем, у меня есть абстрактный класс DrawingObject
. Другой абстрактный класс RectangularObject
наследует от DrawingObject
. Тогда есть несколько конкретных классов, таких как Shape
, Text
, Circle
и т.д., Которые все наследуют от RectangularObject
. Я хочу реализовать ICloneable
на DrawingObject
, а затем перенести его вниз по иерархии, скопировать доступные свойства на каждом уровне и вызвать родителя Clone
на следующем уровне.
Однако проблема заключается в том, что, поскольку первые два класса являются абстрактными, я не могу создать их объекты в методе Clone()
. Таким образом, я должен дублировать процедуру копирования свойств в каждом конкретном классе. Или есть лучший способ?