Lecture 10 Flashcards
What makes a language OO?
- Encapsulation
- Inheritance
- Polymorphism
What are symptoms of bad software?
Confusing: Good software should explain what it’s doing
Rigidity: When making a modification, a lot of other stuff has to be changed
Fragility: Changing something somewhere, which break the software unexpected places and are unrelated to the changes just made
Immobility (no reusability): The desired parts of code is so tightly coupled with undesireable parts, so you can’t use the desireable parts.
What does source code dependency mean in this picture show? here
Here a class (higher level) depends on other classes (lower level) for its functionality.
What are some common problems in bad software?
Spaghetti code, couplin and dependencies
What does run timedependency refere to?
Runtime dependency refers to the relationships between components that are only known and used during the execution of the program, not at compile time.
What makes a language object oriented?
Encapsulation, inheritance and polymorphism (in java also abstraction)
What does the M –> I < - - N mean? here
The dashed arrows between M, I, and N suggest that M doesn’t directly call a specific method on a statically defined N object. Instead, it interacts with an interface I or a base class, and the actual method that is executed could belong to any class that implements I or inherits from the base class. This is where the Pet bernie = new Dog(); example comes into play. At compile time, bernie is known to be of type Pet, but at runtime, it behaves as a Dog, and any method calls it makes will be to Dog methods, not Pet methods, if they are overridden in Dog.
What is coupling?
Degree of interdependence between software modules or components. Shows how closely one module is connected to (or relies) on another.
Low coupling is good, because it makes code more modular and maintable .
High coupling is bad, because the system is less flexible and more error-prone
What is cohesion?
High cohesion means that a module or
class is designed to perform a
specific, clear task, and it doesn’t
contain unrelated or loosely
related functionality.
What are the SOLID principles?
Single responsibility principle: “a class should only have one, and only one, reason
to change”.
Open/closed principle: “software entities should be open for extensions but closed
for modifications”. (Bertrand Meyer 1988)
Liskov substitution principle: “derived classes should be usable through the base
class interface, without the need for the user to know the difference”. (Barbara Liskov 1987)
Interface segregation principle: “many client-specific interfaces are better than
one general-purpose interface”.
Dependency inversion principle: “depend upon abstractions, do not depend upon
concretions”.
What is the OPEN/CLOSED PRINCIPLE?
Software entities should be open for extensions but closed for modifications.
What is single responsibility principle?
A class should only have one responsibility
How is the OPEN/CLOSED PRINCIPLE compromised here? Here
The first slide shows a GraphicEditor class that violates the Open/Closed Principle. It has a method drawShape that determines at runtime which type of shape to draw by using the instanceof operator. This design is problematic because every time you want to add a new shape, you have to modify the drawShape method. This means the class is not closed for modification.
How do we achieve single responsibility principle in a code?
If a class contains multiple methods, you can break those methods down into other classes instead