def_type(Point);
def_type(Shape);
-def_mem(Interface)
+def_mem(PointInterface)
+{
+ void method(move) (Shape self, int x, int y);
+ str method(desc) (Shape self);
+ void method(rename) (Shape self, str name);
+ int count;
+};
+
+def_mem(ShapeInterface)
{
void method(draw) (Shape self);
void method(move) (Shape self, int x, int y);
def_obj(Point)
{
- interface(Interface);
+ interface(PointInterface);
int x1, y1;
str desc;
}
def_mem(Tri)
{
- interface(Interface);
+ interface(ShapeInterface);
Point point;
int x2, y2, x3, y3;
};
def_mem(Rect)
{
- interface(Interface);
+ interface(ShapeInterface);
Point point;
int x2, y2;
};
def_mem(Circ)
{
- interface(Interface);
+ interface(ShapeInterface);
Point point;
int r;
};
-def_community(Shape, Interface);
+def_community(Shape, ShapeInterface);
-/* Note: interface(Interface); has to be at first position in all objects asociated in community */
+/* Note: interface(ShapeInterface); has to be at first position in all objects asociated in community */
def_mem(Object_list)
{
/* Example of using object interface methods from inside constructor methods */
-construct(Tri,Interface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
+construct(Tri,ShapeInterface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
{
self->name = "TRIANGLE";
interface_of(self)->count++;
return self;
}
-construct(Rect,Interface) (Rect self, int x1, int y1, int x2, int y2)
+construct(Rect,ShapeInterface) (Rect self, int x1, int y1, int x2, int y2)
{
self->desc = "rectangle";
interface_of(self)->count++;
return self;
}
-construct(Circ,Interface) (Circ self, int x1, int y1, int r)
+construct(Circ,ShapeInterface) (Circ self, int x1, int y1, int r)
{
self->comment = "Circle";
interface_of(self)->count++;
/* registration of implemented methods to three interfaces of the same type */
-Interface pointInterface(void)
+PointInterface pointInterface(void)
{
- Get_mem(this, Interface);
+ Get_mem(this, PointInterface);
this->draw = NULL;
this->move = movePoint;
return this;
}
-Interface triInterface(void)
+ShapeInterface triInterface(void)
{
- Get_mem(this, Interface);
+ Get_mem(this, ShapeInterface);
this->draw = drawTri;
this->move = moveTri;
return this;
}
-Interface rectInterface(void)
+ShapeInterface rectInterface(void)
{
- Get_mem(this, Interface);
+ Get_mem(this, ShapeInterface);
this->draw = drawRect;
this->move = moveRect;
return this;
}
-Interface circInterface(void)
+ShapeInterface circInterface(void)
{
- Get_mem(this, Interface);
+ Get_mem(this, ShapeInterface);
this->draw = drawCirc;
this->move = moveCirc;
program
{
- Interface triangles = triInterface();
- Interface rectangles = rectInterface();
- Interface circles = circInterface();
+ ShapeInterface triangles = triInterface();
+ ShapeInterface rectangles = rectInterface();
+ ShapeInterface circles = circInterface();
Object_list all = NULL, one;
one = get_mem(Object_list);