Lecture 10 Flashcards

1
Q

What makes a language OO?

A
  • Encapsulation
  • Inheritance
  • Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are symptoms of bad software?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does source code dependency mean in this picture show? here

A

Here a class (higher level) depends on other classes (lower level) for its functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some common problems in bad software?

A

Spaghetti code, couplin and dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does run timedependency refere to?

A

Runtime dependency refers to the relationships between components that are only known and used during the execution of the program, not at compile time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What makes a language object oriented?

A

Encapsulation, inheritance and polymorphism (in java also abstraction)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the M –> I < - - N mean? here

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is coupling?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is cohesion?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the SOLID principles?

A

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”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the OPEN/CLOSED PRINCIPLE?

A

Software entities should be open for extensions but closed for modifications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is single responsibility principle?

A

A class should only have one responsibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is the OPEN/CLOSED PRINCIPLE compromised here? Here

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do we achieve single responsibility principle in a code?

A

If a class contains multiple methods, you can break those methods down into other classes instead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Liskov substitution principle?

A

Any subclass should be able to be used just like the base class.
Football (sub class) should be able to substitue Ball (superclass)

17
Q

What is INTERFACE SEGREGATION PRINCIPLE?

A

Many client-specific interfaces are better than one general-purpose interface.

18
Q

What can break the Liskov substitution principle (LSP)?

A

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.

19
Q

What is dependency inversion principle?

A

Depending upon interfaces or abstract functions and classes rather than upon concrete functions and classes.

20
Q

How do we achieve dependency inversion principle (DIP)?

A

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.

21
Q

Coupling and cohesion. Explain.

A

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.

22
Q

What is desireable in a class?

A

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.