Skip to main content
deleted 13 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

The Foo#policy method seems ok.

I think the main problem is PolicyX#pass? method.

As it ismethod; at the moment it is exposing too much, to. To use it, you have to know about the collaborators of the PolicyX class.

A good solution could be to inject collaborators when you instantiate the object.

Lets Lets make an example with PolicyC

class PolicyC def initialize(collaborator_a,collaborator_b) @collaborator_a = collaborator_a @collaborator_b = collaborator_b end def pass? @collaborator_a.check? && collaborator_b.check? # end end 

The Foo#policy method seems ok.

I think the main problem is PolicyX#pass? method.

As it is at the moment it is exposing too much, to use it you have to know about the collaborators of the PolicyX class.

A good solution could be to inject collaborators when you instantiate the object.

Lets make an example with PolicyC

class PolicyC def initialize(collaborator_a,collaborator_b) @collaborator_a = collaborator_a @collaborator_b = collaborator_b end def pass? @collaborator_a.check? && collaborator_b.check? # end end 

The Foo#policy method seems ok.

I think the main problem is PolicyX#pass? method; at the moment it is exposing too much. To use it, you have to know about the collaborators of the PolicyX class.

A good solution could be to inject collaborators when you instantiate the object. Lets make an example with PolicyC

class PolicyC def initialize(collaborator_a,collaborator_b) @collaborator_a = collaborator_a @collaborator_b = collaborator_b end def pass? @collaborator_a.check? && collaborator_b.check? # end end 
Source Link

The Foo#policy method seems ok.

I think the main problem is PolicyX#pass? method.

As it is at the moment it is exposing too much, to use it you have to know about the collaborators of the PolicyX class.

A good solution could be to inject collaborators when you instantiate the object.

Lets make an example with PolicyC

class PolicyC def initialize(collaborator_a,collaborator_b) @collaborator_a = collaborator_a @collaborator_b = collaborator_b end def pass? @collaborator_a.check? && collaborator_b.check? # end end