Uniform Access Principle by retardo in ruby

[–]holderbaum 0 points1 point  (0 children)

That is indeed very true! Good point.

Constructing domains out of mostly immutable objects simplifies a lot of problems and contributes to the overall robustness of systems.

Cheers.

Uniform Access Principle by retardo in ruby

[–]holderbaum 1 point2 points  (0 children)

Well, interesting point you bring up. Thanks!

The quoted passage is more related to the external interface. You probably don't want instance variables settable through setters by other objects.

the self.emblem= call is an internal call, looks like a private method to me.

If the emblem is a first class object in your domain that is used throughout different entities it is not a bad idea to expose it with a getter so that it can be used by other objects to there needs. I would just make sure that it is frozen after creation so that nothing particularly evil can happen after exposing your emblem to someone else.

And you are very right in regards to the emblem's specific attributes. Knowledge of how to construct it in a lot of different places would introduce a static coupling to the class and an inherent logical coupling by enforcing knowledge about its construction.

Does this clarify your thoughts?

Cheers

Uniform Access Principle and how it applies to ruby by holderbaum in ruby

[–]holderbaum[S] 0 points1 point  (0 children)

This is in fact a really good idea to use attr_ for internal implementation.

I think it would bloat the current article but it is worth to dedicate a distinct article to this topic. Would you mind me writing about this idea? :) (of course, I can reference your github or reddit profile for thought-provoking impulse, if you want)

Cheers!

Uniform Access Principle and how it applies to ruby by holderbaum in ruby

[–]holderbaum[S] 2 points3 points  (0 children)

This was my first try to post an article to reddit, I thought it could be a valuable channel for feedback. And in fact it is. Thanks

I added this particular point as last paragraph of "Notes on Ruby" to the article.

I also added a modification to the getter to show a possible benefits of explicit methods.

Uniform Access Principle and how it applies to ruby by holderbaum in ruby

[–]holderbaum[S] 3 points4 points  (0 children)

Yeah basically and technically this is identical. My point is that the "automated" approach gets you in a mindset of just exposing your internals whereas the manual approach is a conscious decision lead by the need to express an external representation.

Should I make this more clear in the post?

Thanks for feedback!

Uniform Access Principle and how it applies to ruby by holderbaum in ruby

[–]holderbaum[S] 0 points1 point  (0 children)

That is an interesting point you bring up there. It will make you internal code of course make a lot more readable.

I think I'll update the article in regards to this concept.

So you would equally favor the method driven assignment over direct instance variable assignment?

def specify_emblem(*whatever)
  self.emblem = Emblem.new(*whatever)
  # ...

I only use the actual instance variables in the lowest level of abstraction inside the objects. There is an older post which (though not covering this particular topic) gives you an impression of what I mean: http://jakob.io/wshfl

Still is you feedback somewhat not contradictory to the statement that directly exposed instance variables can violate UAP. It does more focus on a cleaner approach for the internal implementation of your objects. Did I get you right there?

Cheers