File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 26
26
Describes a group of objects that is treated as a single instance.
27
27
"""
28
28
29
+ from abc import ABC , abstractmethod
30
+ from typing import List
29
31
30
- class Graphic :
31
- def render (self ):
32
- raise NotImplementedError ("You should implement this." )
32
+
33
+ class Graphic (ABC ):
34
+ @abstractmethod
35
+ def render (self ) -> None :
36
+ raise NotImplementedError ("You should implement this!" )
33
37
34
38
35
39
class CompositeGraphic (Graphic ):
36
- def __init__ (self ):
37
- self .graphics = []
40
+ def __init__ (self ) -> None :
41
+ self .graphics : List [ Graphic ] = []
38
42
39
- def render (self ):
43
+ def render (self ) -> None :
40
44
for graphic in self .graphics :
41
45
graphic .render ()
42
46
43
- def add (self , graphic ) :
47
+ def add (self , graphic : Graphic ) -> None :
44
48
self .graphics .append (graphic )
45
49
46
- def remove (self , graphic ) :
50
+ def remove (self , graphic : Graphic ) -> None :
47
51
self .graphics .remove (graphic )
48
52
49
53
50
54
class Ellipse (Graphic ):
51
- def __init__ (self , name ) :
55
+ def __init__ (self , name : str ) -> None :
52
56
self .name = name
53
57
54
- def render (self ):
55
- print ("Ellipse: {}" . format ( self .name ) )
58
+ def render (self ) -> None :
59
+ print (f "Ellipse: { self .name } " )
56
60
57
61
58
62
def main ():
You can’t perform that action at this time.
0 commit comments