inheritance - Objective-C subclass initWithSuperClass -


The rectangle and the normal superclass size of the circle.

If I start some shapes, then is it better to change the shape in a circle and set it when setting the same property? Should I apply an initWithShape to such subclasses that looks something like this?

  - (id) initWithShape: (size *) aShape {self = (id) aape; // set circle or rectangle specific value self back; }  

Does anyone have an example that I can see?

You can not make it after an object, leaving it and creating a new one (which you Except in an init method, and is actually done often for singletons or class clusters), but this is not really what you are doing.

With some properties, give an existing shape object, your only real option is to create a new object based on the shape properties. Something like this:

In size: m:

  - (id) initWithShape: (size *) aShape {self = [init init]; If (self! = Zero) {// copy general properties _x = aShape.x; _y = aShape.y; _color = [copy aShape.color]; } Healthy return; }  

In Circle.M:

  - (id) initWithShape: (size *) aShape {self = [super initWithShale: aShape]; If there are basic properties on the square of the shape (if: [ashp iskindoffclass: [oval class]]) {// average radius _radius = (average for small (oval *) and diameter AShape shortDiameter] + [(oval *) aShape longDiameter]) / 4; } Use Else {// or normal size methods _radius = aShape.size / 2; }} Self-back; }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -