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
What is Liskov substitution principle?
Any subclass should be able to be used just like the base class.
Football (sub class) should be able to substitue Ball (superclass)
What is INTERFACE SEGREGATION PRINCIPLE?
Many client-specific interfaces are better than one general-purpose interface.
What can break the Liskov substitution principle (LSP)?
If the super class and the subclasses don’t share the same variables and attributes. The super class Bird, has the method fly()
and the subclass Ostrich also has the method, but an Ostrict can’t fly, therefore it breaks the LSP.
What is dependency inversion principle?
Depending upon interfaces or abstract functions and classes rather than upon concrete functions and classes.
How do we achieve dependency inversion principle (DIP)?
Making sure that higher-level components don’t depend on lower-level components.
Say we have a car engine. When that changes, the way we drive the car’s steering wheel should NOT change, it should drive the same.
Coupling and cohesion. Explain.
Coupling: degree of interdependence between software modules or components. How closely a module is connected to or relies on another.
Cohesion: degree to which the functionality within a module is related and
focused on a single, well-defined purpose.
What is desireable in a class?
Low coupling and high cohesion are desirable
low coupling as it means there’s not much dependency, therefore flexibility.
High cohesion mean that a class is designed to perform a specific task.