Skip to content

Commit 563f805

Browse files
committed
edited composite
1 parent 0b5a6bd commit 563f805

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

composite/classes.dot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
digraph "classes" {
22
charset="utf-8"
33
rankdir=BT
4-
"0" [label="{CompositeGraphic|child_graphics : list\l|add()\lprint()\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()\lfunc()\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
}

composite/composite.png

7.58 KB
Loading

composite/composite.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,47 @@
11
from abc import ABCMeta, abstractmethod
22

3-
43
class 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"""
4029
ELLIPSE1 = Ellipse()
41-
ELLIPSE2 = Ellipse()
42-
ELLIPSE3 = Ellipse()
43-
ELLIPSE4 = Ellipse()
4430
CIRCLE1 = 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

5135
COMPOSITE2 = CompositeGraphic()
52-
COMPOSITE2.add(ELLIPSE4)
5336
COMPOSITE2.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()

0 commit comments

Comments
 (0)