Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: Re: Short Refactoring Tip: let the object do it for you

by mvc (Scribe)
on May 22, 2003 at 11:38 UTC ( #260032=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Short Refactoring Tip: let the object do it for you
in thread Short Refactoring Tip: let the object do it for you

Here we have a classic conflict of design forces:

  • Encapsulation
  • Seperation of concerns (cohesion)

If you put the UI code in the object, you are encapsulated but your object is now doing its regular work + UI work (low cohesion). If you keep it as is, you get clean seperation of concerns, but break encapsulation.

There are other solutions that could balance these forces better. The balance of forces you want depends on your requirements.

You could, for example, have the template code look like this:

<% item.getReceivedUI("<input ...>") %>

The item object getReceivedUI() will check if receive is possible, if so interpolate the parameter as a TT template with item.received in the stash. If not, it returns item.received. Then you remove the UI code from the item object by delegating the actual interpolation to some strategy object, that may use TT or anything. Thus the item knows not about UI, just about presentation logic. The template is still in charge of the UI. Is this extra work worth it? Depends on your requirements.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://260032]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-08-12 03:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found