File tree Expand file tree Collapse file tree 3 files changed +21
-38
lines changed Expand file tree Collapse file tree 3 files changed +21
-38
lines changed Original file line number Diff line number Diff line change 11digraph " classes" {
22charset=" utf-8"
33rankdir =BT
4- " 0" [label =" {CompositeGraphic|child_graphics : list\l |add()\l print ()\l }" , shape =" record" ];
5- " 1" [label =" {Ellipse |\l |print ()\l }" , shape =" record" ];
6- " 2" [label =" {IGraphic |\l |print ()\l }" , shape =" record" ];
4+ " 0" [label =" {Composite|entities : list\l |add()\l func ()\l }" , shape =" record" ];
5+ " 1" [label =" {Entity |\l |func ()\l }" , shape =" record" ];
6+ " 2" [label =" {IEntity |\l |func ()\l }" , shape =" record" ];
77" 0" -> " 2" [arrowhead =" empty" , arrowtail =" none" ];
88" 1" -> " 2" [arrowhead =" empty" , arrowtail =" none" ];
99}
Original file line number Diff line number Diff line change 11from abc import ABCMeta , abstractmethod
22
3-
43class IGraphic (metaclass = ABCMeta ):
5- """Component"""
6-
74 @staticmethod
85 @abstractmethod
96 def print ():
107 """print information"""
118
9+ class Ellipse (IGraphic ):
10+ def print (self ):
11+ print ("Ellipse" )
1212
13- class CompositeGraphic (IGraphic ):
14- """Composite"""
13+ class Circle (IGraphic ):
14+ def print (self ):
15+ print ("Circle" )
1516
17+ class CompositeGraphic (IGraphic ):
1618 def __init__ (self ):
1719 self .child_graphics = []
1820
1921 def add (self , graphic ):
2022 self .child_graphics .append (graphic )
21-
23+
2224 def print (self ):
2325 for g in self .child_graphics :
2426 g .print ()
2527
2628
27- class Ellipse (IGraphic ):
28- """leaf"""
29-
30- def print (self ):
31- print ("Ellipse" )
32-
33-
34- class Circle (IGraphic ):
35- def print (self ):
36- print ("Circle" )
37-
38-
39- """client"""
4029ELLIPSE1 = Ellipse ()
41- ELLIPSE2 = Ellipse ()
42- ELLIPSE3 = Ellipse ()
43- ELLIPSE4 = Ellipse ()
4430CIRCLE1 = Circle ()
4531
46- COMPOSITE4 = CompositeGraphic ()
47- COMPOSITE4 .add (ELLIPSE1 )
48- COMPOSITE4 .add (ELLIPSE2 )
49- COMPOSITE4 .add (ELLIPSE3 )
32+ COMPOSITE1 = CompositeGraphic ()
33+ COMPOSITE1 .add (ELLIPSE1 )
5034
5135COMPOSITE2 = CompositeGraphic ()
52- COMPOSITE2 .add (ELLIPSE4 )
5336COMPOSITE2 .add (CIRCLE1 )
37+ COMPOSITE2 .add (COMPOSITE1 )
38+
39+ COMPOSITE2 .print ()
40+
41+
42+
43+ # ELLIPSE1.print()
44+ # CIRCLE1.print()
5445
55- COMPOSITE3 = CompositeGraphic ()
56- COMPOSITE3 .add (COMPOSITE4 )
57- COMPOSITE3 .add (COMPOSITE2 )
5846
59- COMPOSITE1 = CompositeGraphic ()
60- COMPOSITE1 .add (ELLIPSE1 )
61- COMPOSITE1 .add (COMPOSITE3 )
62- # COMPOSITE3.print()
6347
64- COMPOSITE1 .print ()
You can’t perform that action at this time.
0 commit comments