From 24fe750d3498c33fd8651eb96f429f6591cec2d5 Mon Sep 17 00:00:00 2001 From: xchaos Date: Fri, 22 Aug 2008 14:28:38 +0000 Subject: [PATCH] some work git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@84 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- demos/objects/objects-hierarchy.c | 50 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/demos/objects/objects-hierarchy.c b/demos/objects/objects-hierarchy.c index d81d271..4c81c7b 100644 --- a/demos/objects/objects-hierarchy.c +++ b/demos/objects/objects-hierarchy.c @@ -5,7 +5,15 @@ 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); @@ -20,35 +28,35 @@ def_mem(Interface) 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) { @@ -194,7 +202,7 @@ void nameRect(Shape community, str newname) /* 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++; @@ -203,7 +211,7 @@ construct(Tri,Interface) (Tri self, int x1, int y1, int x2, int y2, int x3, int 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++; @@ -212,7 +220,7 @@ construct(Rect,Interface) (Rect self, int x1, int y1, int x2, int y2) 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++; @@ -223,9 +231,9 @@ construct(Circ,Interface) (Circ self, int x1, int y1, int r) /* 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; @@ -238,9 +246,9 @@ Interface pointInterface(void) return this; } -Interface triInterface(void) +ShapeInterface triInterface(void) { - Get_mem(this, Interface); + Get_mem(this, ShapeInterface); this->draw = drawTri; this->move = moveTri; @@ -253,9 +261,9 @@ Interface triInterface(void) return this; } -Interface rectInterface(void) +ShapeInterface rectInterface(void) { - Get_mem(this, Interface); + Get_mem(this, ShapeInterface); this->draw = drawRect; this->move = moveRect; @@ -268,9 +276,9 @@ Interface rectInterface(void) return this; } -Interface circInterface(void) +ShapeInterface circInterface(void) { - Get_mem(this, Interface); + Get_mem(this, ShapeInterface); this->draw = drawCirc; this->move = moveCirc; @@ -287,9 +295,9 @@ Interface circInterface(void) 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); -- 2.30.2