Stage 4: Interface introduced
Stage 4: Interface introduced
Highlights:
The question is where to define or implement a behavior only for certain birds.
The solution is to use interfaces, which are prefixed with "I" and denote objects that support a certain behavior.
Interfaces are like pure abstract classes, meaning they only define a contract and not implementation.
The implementation will be provided by the specific child that adheres to the interface.
The "ISingable" interface is used for birds that can sing, and if a class doesn't implement it, there will be an error.
An example of a bird that doesn't implement the interface is the eagle, which cannot sing.
By having well-defined contracts, developers are prevented from using objects in ways they're not supposed to.
This provides an additional layer of robustness while keeping everything neat and understandable.
Animal.cs
No change!
Bird.cs
No change!
Cat.cs
No change!
Dog.cs
No change!
Eagle.cs
ISingable.cs
Parrot.cs
Program.cs
Last updated