Bindings, Platforms, and Innovation
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
Tracking change and innovation in the enterprise software development community
Posted by Sebastien Auvray on Oct 25, 2007 09:00 AM
The Law of Demeter or Principle of Least Knowledge is a design guideline for developing software. The fundamental notion is that a given object should assume as little as possible about the structure, properties and behavior of anything else (including its subcomponents). Dan Manges helped to clarify the concept and the way to apply it in Ruby, notably through the use of the Forwardable module. Using mocks and stubs, Luke Redpath came across Demeter's law violation when writing his Unit Tests:The solution is to add a delegate method on all your models. But that quickly becomes boring, which is the reason why Luke introduced the Demeter's Revenge plugin which will create a collection of Demeter-compliant methods for yourclass WidgetsControllerCreateActionTest < Test::Unit::TestCase
def setup
# usual rails controller test setup here
@user = mock('user')
User.stubs(:find).returns(@user)
end
def test_should_create_new_widget_for_parent_user_using_posted_widget_params
widgets_proxy = mock('association proxy')
@user.stubs(:widgets).returns(widgets_proxy)
# Demeter's Law Violation here by using the widget_proxy through User object
widgets_proxy.expects(:create).with(:name => 'my funky widget')
post :create, :widget => {:name=> 'my funky widget'}end
has_many and has_and_belongs_to_many associations:# given a User that has_many Widgets you'll be able to use:
user.build_widget(params) # => user.widgets.build(params)
user.create_widget(params) # => user.widgets.create(params)
# ...
But aren't laws made to be broken? And the fact that a plugin can automate a so called "Law" isn't this making it null and void?
The Agile Business Analyst: Skills and Techniques needed for Agile
Agile Development: A Manager's Roadmap for Success
I thought I'd made this clear on my blog but I'd like to respond to the final comment regarding a law being null and void because it can apparently be "fixed automatically". My plugin targets a very specific instance of demeter violation - that is, violations found in the inherent design of ActiveRecord - and nothing more. I wasn't happy with the way ActiveRecord practically forces you into breaking encapsulation by exposing the internals of its associations and the pain felt writing stubs and mocks is simply what drove me to finally do something about it; thanks to Ruby's dynamic nature, I was able to save myself writing the same repetitive wrapper (encapsulating) methods time and time again. I'm sure most readers will recognise that there is far more to the law of demeter than the one specific issue that my plugin sets out to solve and if you'd like to read more google provides a variety of articles on the subject. I'm somewhat concerned that some people seem to be interpreting this plugin as some kind of 'silver bullet' for all of your demeter violating woes (I thought I was quite explicit about that) and my blog entry links to some other articles that explore the fundamental issues more closely which I encourage people to read.
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.
This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.
This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.
This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.
After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.
IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.
Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.
1 comment
Watch Thread Reply