L7: Making Software Reusable Flashcards
What is a “type”?
- Primitive types are variables that store actual values
- Reference types store references to an object T
Abstract classes versus interfaces
Neither can be instantiated as object, both can specify behaviour and data
An interface is a collection of behaviour offered by an object of that type:
- Methods are defined but empty, all of them must be implemented in the class
- A class can implement multiple interfaces, since interfaces are not inheritance
An abstract class is abstracted behaviour of a collection of classes:
- Methods can be abstract (no implementation) or concrete (with implementation)
- Are (should be) part of an inheritance structure
Enumeration (enums)
- Set of fixed values/constants
- Can be used in switches, loops, …
- Can also involve methods
Record
Designed to store fixed values
Automatically have:
- Private field for each component
- Public getter
- Public constructor
- Implemented toString() method
SOLID
- Single responsibility: each unit (class) should have only one responsibility
- Open/closed: units should be open for extensions, but closed for modifications
- Liskov substitution: methods that use references to classes must be able to use objects of derived classes (i.e. subclasses) without knowing it
- Interface segregation: no code should be required to rely on methods it is not using
- Dependency inversion: higher-level units should not depend on lower-level units, and both should depend on abstractions
KISS: Keep It Simple, Silly!
It does not help to have a complicated solution nobody understands
Simpler solutions are less error-prone