Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Law of Demeter

Law of Demeter

Rajiv Abraham

July 24, 2015
Tweet

Other Decks in Programming

Transcript

  1. What is the Law of Demeter? From an object, one

    can only call methods of: - The object itself. - An argument of the method. - Any object created within the method. - Any direct properties/fields of the object. - **Global Instances accessible by the object
  2. Purpose: Hide Internals to hide change class PushNotifier ... def

    article_primary_tag_uris push_alert.article.resource_tags.select { |tag| tag.isPrimary? }.map(&:uri) end end
  3. LoD Smells • Private Methods hiding the chain • Delegate

    Explosion • Or Use Rails Delegate? OR ...
  4. Is this giving me design feedback? • Maybe this class

    has too many associations?(violation of the Single Responsibility Principle) • Pass in data via constructor/method arguments? So someone else above now does what this class is doing?