Chapter 8 Flashcards

1
Q

Composition

A

by using object-oriented composition to combine simple, independent objects into larger, more complex wholes . In composition, the larger object is connected to its parts via a has-a relationship. A bicycle has parts. Bicycle is the containing object , the parts are contained within a bicycle. Inherent in the definition of composition is the idea that, not only does a bicycle have parts , but it communicates with them via an interface . Part is a role and bicycles are happy to collaborate with any object that plays the role.

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

Composition

A

by using object-oriented composition to combine simple, independent objects into larger, more complex wholes . In composition, the larger object is connected to its parts via a has-a relationship. A bicycle has parts. Bicycle is the containing object , the parts are contained within a bicycle. Inherent in the definition of composition is the idea that, not only does a bicycle have parts , but it communicates with them via an interface . Part is a role and bicycles are happy to collaborate with any object that plays the role.

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

OpenStruct

A

Ruby’s OpenStruct class is a lot like the Struct class that you’ve already seen, it provides a convenient way to bundle a number of attributes into an object. The difference between the two is that Struct takes position order initialization arguments while OpenStruct takes a hash for its initialization and then derives attributes from the hash.

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

OpenStruct

A

Ruby’s OpenStruct class is a lot like the Struct class that you’ve already seen, it provides a convenient way to bundle a number of attributes into an object. The difference between the two is that Struct takes position order initialization arguments while OpenStruct takes a hash for its initialization and then derives attributes from the hash.

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

Delegation

A

delegation is when one object receives a message and merely forwards it to another. Delegation creates dependencies; the receiving object must recognize the message and know where to send it.

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

Delegation

A

delegation is when one object receives a message and merely forwards it to another. Delegation creates dependencies; the receiving object must recognize the message and know where to send it.

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

Chapter 8 Summary

A

Composition allows you to combine small parts to create more complex objects such that the whole becomes more than the sum of its parts. Composed objects tend to consist of simple, discrete entities that can easily be rearranged into new combinations. These simple objects are easy to understand, reuse, and test, but because they combine into a more complicated whole, the operation of the bigger application may not be as easy to understand as that of the individual parts.

Composition, classical inheritance, and behavior sharing via modules are competing techniques for arranging code. Each has different costs and benefits; these differences predispose them to be better at solving slightly different problems.

These techniques are tools, nothing more, and you’ll become a better designer if you practice each of them. Learning to use them properly is a matter of experience and judgment, and one of the best ways to gain experience is to learn from your own mistakes. The key to improving your design skills is to attempt these techniques, accept your errors cheerfully, remain detached from past design decisions, and refactor mercilessly.

As you gain experience, you’ll get better at choosing the correct technique the first time, your costs will go down, and your applications will improve.

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