Plenty of part-time jobs are available for teens, college students, moms, retirees, and anyone seeking to earn extra money. For details contact: www.phoenixwfh...
(unixf48e) Ten minutes to submit your resume can take your career 10 Times ahead! View Over 2, 00, 000 job openings. Receive matching jobs on your email twice...
Online data entry job get payout monthly. The internet brings to you an excellent home based business opportunity to earn online with your convenient timings. Genuine...
I want to show you a way you can “draw a line” between your application “main logic” and your Rails controllers.
In this example I will compare a new approach with the one that I took in my last post about thinking in small programs
This example is from an application that provides “web sites” for companies. Something similar to tumblr but for companies.
In the application the “site” of the company is not public by default. And in order to be published the admin of the company must filled the “phrase” and “description” of the company.
Working with this information and thinking in designing small programs we can propose the next solution.
But as you can see even though we are abstracting the knowledge about the site we are having a lot of “control” logic. This does not sound very bad because we are in a “controller” but I think the Rails controllers should be dealing just with the communication stuff merging all the pieces together. I saw them must as objects that knows “who” can make something rather than “how” something can be made.
So I want to propose another solution. I want to draw a line between the things that makes something and the thing that knows when those other things are “called”.
I will use what Ivar Jacobson calls “control object” in his book Object-Oriented software engineering (or at least what I understand it is).
The control objects model functionality that is not naturally tied to any other object, for example, behavior that consist of operating on several different entity objects, doing some computations and then returning the result to an interface object.
I know I can declare those “callbacks” as methods in the controller and just pass the controller to the Sites.publish_company_site method, but I think this is far more explicit.
As you see know the controller still knows that an active record object can update its attributes, but doesn’t know when and which attributes to update. Also knows how (I think this “how” is ok =)) to redirect but doesn’t know when to do it or the message that is set.
With this solution we are extracting a more of the application rules from the framework and also we are expressing them in “simple” ruby objects that I think every ruby programmer can understand.
And as we have test that run really fast, if you need to make a change on the behavior you will be able to do it with confidence =).