Ruby practical object oriented design Flashcards

1
Q

Why is design important in object-oriented programming?

A

Design is crucial because changes in applications are inevitable. Without proper design, changes can be difficult due to dependencies between objects and assumptions made by tests about object construction.

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

What is the primary goal of good design?

A

The primary goal of good design is to reduce the cost of change in the future. It aims to provide flexibility and adaptability to accommodate future modifications and enhancements.

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

What are the tools of design in object-oriented programming?

A

The tools of design include design principles such as SOLID principles (Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion), the Don’t Repeat Yourself principle, the Law of Demeter, and design patterns.

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

What is the Single Responsibility Principle (SRP)?

A

SRP states that a class should have only one reason to change, meaning it should have only one responsibility. This principle promotes modular and maintainable code.

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

How does Agile software development relate to design?

A

Agile software development emphasizes iterative and incremental development, avoiding Big Up Front Design (BUFD). Design decisions are made incrementally based on the information available at the time, rather than trying to anticipate all requirements upfront.

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

What is the significance of design patterns in object-oriented programming?

A

Design patterns provide simple and elegant solutions to recurring problems in OOP. They enhance flexibility, modularity, reusability, and understandability of designs. Understanding design patterns helps in making informed design decisions.

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

How can design fail in object-oriented programming?

A

Design can fail when principles are applied inappropriately, patterns are misapplied, or when the act of design is separated from programming. Design failures can lead to rigid and difficult-to-maintain codebases.

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

What metrics can be used to judge the quality of design?

A

Metrics such as adherence to OOD principles, code complexity, and maintainability can be used to assess design quality. However, good scores in these metrics do not guarantee ease of future changes, as applications may still anticipate the wrong future or implement the wrong functionality efficiently.

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

How does experience influence design decisions?

A

With experience, developers learn to apply design principles and patterns effectively. They understand the tradeoff between time spent on design and the time saved in future maintenance. Over time, developers become adept at making design decisions at the right time and in the right amount.

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

What is the key principle of designing classes with a single responsibility?

A

The key principle is that a class should do the smallest possible useful thing. This means creating classes that have clear and focused responsibilities, making them easier to understand, maintain, and change.

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

How can you determine if a class has a single responsibility?

A

There are two techniques:

Ask questions for each of its methods. If each method’s purpose makes sense within the context of the class, it likely has a single responsibility.

Describe the class in one sentence. If the description contains the words “and” or “or,” or if the class does much more than the description suggests, it likely has more than one responsibility.

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

What are the qualities of code that embraces change?

A

Code that embraces change:

Has no unexpected side effects when changed.

Requires small changes in code for small changes in requirements.

Is easy to reuse.

Makes adding new code, which is easy to change, the easiest way to make a change.

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

How should instance variables be handled in classes?

A

Instance variables should be hidden, and wrapper methods should be used instead of directly accessing them. This encapsulation protects the class’s internal state and allows for easier changes in the future.

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

What is the benefit of isolating extra responsibilities in classes?

A

Isolating extra responsibilities in classes clarifies what each class does, reduces the need for comments, encourages reuse, and makes it easier to move responsibilities to another class if needed. It ensures that each class has a single, well-defined purpose.

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