File tree Expand file tree Collapse file tree
02.problem.method-overriding
04.polymorphism/01.problem.substitutability
05.composition-vs-inheritance/01.problem.when-to-use Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,9 +11,5 @@ it with specific shapes like `Circle` and `Rectangle`.
11114 . Create a ` Rectangle ` class that extends ` Shape `
12125 . Add ` width ` and ` height ` fields to ` Rectangle `
1313
14- 💰 Use ` extends ` to inherit fields and methods from a base class.
15-
16- 💰 Don't forget to call ` super() ` in the constructor if the parent has a
17- constructor.
1814
1915📜 [ TypeScript Handbook - Inheritance] ( https://www.typescriptlang.org/docs/handbook/2/classes.html#inheritance )
Original file line number Diff line number Diff line change @@ -10,8 +10,5 @@ method to provide its own implementation.
10103 . Override ` getArea() ` in ` Rectangle ` to return width × height
11114 . Optionally use ` super ` to call the parent method
1212
13- 💰 Override a method by redefining it in the subclass.
14-
15- 💰 You can call ` super.method() ` to use the parent's implementation if needed.
1613
1714📜 [ TypeScript Handbook - Overriding Methods] ( https://www.typescriptlang.org/docs/handbook/2/classes.html#overriding-methods )
Original file line number Diff line number Diff line change @@ -11,6 +11,5 @@ We'll use polymorphism to handle all media types uniformly.
11114 . Create a ` MediaPlayer ` class with a method that accepts ` MediaFile `
12125 . Demonstrate that both ` AudioFile ` and ` VideoFile ` can be used interchangeably
1313
14- 💰 Accept the base class type so any subclass can be used.
1514
1615📜 [ TypeScript Handbook - Classes] ( https://www.typescriptlang.org/docs/handbook/2/classes.html )
Original file line number Diff line number Diff line change @@ -11,18 +11,6 @@ inheritance or composition for different scenarios.
11114 . Create a ` ConsoleLogger ` class that uses inheritance (is-a Logger)
12125 . Demonstrate when each approach is appropriate
1313
14- 💰 Inheritance (is-a):
15-
16- - ` FileLogger ` IS-A ` Logger `
17- - ` ConsoleLogger ` IS-A ` Logger `
18- - They are specializations of Logger
19-
20- 💰 Composition (has-a):
21-
22- - ` EmailService ` HAS-A ` Logger `
23- - EmailService uses logging but isn't a type of logger
24- - Can swap different loggers at runtime
25-
2614💰 Think about the relationship: Is it "is-a" or "has-a"?
2715
2816📜 [ Composition over Inheritance] ( https://en.wikipedia.org/wiki/Composition_over_inheritance )
You can’t perform that action at this time.
0 commit comments