Chapter 3 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Dependencies

A

An object depends on another object if, when one object changes, the other might be forced to change in turn.

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

Dependency Injection

A

Using dependency injection to shape code relies on your ability to recognize that the responsibility for knowing the name of a class and the responsibility for knowing the name of a message to send to that class may belong in different objects.

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

Dependency Injection

A

Using dependency injection to shape code relies on your ability to recognize that the responsibility for knowing the name of a class and the responsibility for knowing the name of a message to send to that class may belong in different objects.

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

Use Hashes for Initialization Arguments.

A
class Gear
   attr_reader :chainring, :cog, :wheel
   def initialize(args)
     @chainring = args[:chainring]
     @cog = args[:cog]
     @wheel = args[:wheel] 
   end
end

Removes every dependency on argument order.
The key names in the hash furnish explicit documentation about the arguments.

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

Use Hashes for Initialization Arguments.

A
class Gear
   attr_reader :chainring, :cog, :wheel
   def initialize(args)
     @chainring = args[:chainring]
     @cog = args[:cog]
     @wheel = args[:wheel] 
   end
end

Removes every dependency on argument order.
The key names in the hash furnish explicit documentation about the arguments.

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

fetch

A

The fetch method expects the key you’re fetching to be in the hash and supplies several options for explicitly handling missing keys.

def initialize(args)
  @wheel = args.fetch(:wheel, 40)
  @cog = args.fetch(:cog, 1)
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Factory

A

An Object used to create other objects.

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

Summary

A

Dependency management is core to creating future-proof applications. Injecting dependencies creates loosely coupled objects that can be reused in novel ways. Isolating dependencies allows objects to quickly adapt to unexpected changes. Depending on abstractions decreases the likelihood of facing these changes.

The key to managing dependencies is to control their direction. The road to maintenance nirvana is paved with classes that depend on things that change less often than they do.

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