Note that there are some explanatory texts on larger screens.

plurals
  1. POSeparation of concerns; MVC; why?
    text
    copied!<p>I'm currently reading up on OO before I embark upon my next major project. To give you some quick background, I'm a PHP developer, working on web applications. </p> <p>One area that particularly interests me is the User Interface; specifically how to build this and connect it to my OO "model".</p> <p>I've been doing some reading on this area. One of my favourites is this: <a href="http://www.javaworld.com/javaworld/jw-07-1999/jw-07-toolbox.html" rel="nofollow noreferrer">Building user interfaces for object-oriented systems</a> </p> <blockquote> <p>"All objects must provide their own UI"</p> </blockquote> <p>Thinking about <em>my</em> problem, I can see this working well. I build my "user" object to represent someone who has logged into my website, for example. One of my methods is then "display_yourself" or similar. I can use this throughout my code. Perhaps to start with this will just be their name. Later, if I need to adjust to show their name+small avatar, I can just update this one method and hey-presto, my app is updated. Or if I need to make their name a link to their profile, hey-presto I can update again easily from one place.</p> <p>In terms of an OO system; I think this approach works well. Looking on other StackOverflow threads, I found this under "Separation of Concerns": <a href="https://stackoverflow.com/questions/98734/separation-of-concerns">Soc</a></p> <blockquote> <p>"In computer science, separation of concerns (SoC) is the process of breaking a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. Progress towards SoC is traditionally achieved through modularity and encapsulation, with the help of information hiding."</p> </blockquote> <p>To my mind I have achieved this. My user object hides all it's information. I don't have any places in my code where I say $user->get_user_name() before I display it.</p> <p>However, this seems to go against what other people seem to think of as "best practice". </p> <p>To quote the "selected" (green one) answer from the same question:</p> <blockquote> <p>"The separation of concerns is keeping the code for each of these concerns separate. Changing the interface should not require changing the business logic code, and vice versa. Model-View-Controller (MVC) design pattern is an excellent example of separating these concerns for better software maintainability."</p> </blockquote> <p>Why does this make for better software maintainability? Surely with MVC, my View has to know an awful lot about the Model? Read the JavaWorld article for a detailed discussion on this point: <a href="http://www.javaworld.com/javaworld/jw-07-1999/jw-07-toolbox.html" rel="nofollow noreferrer">Building user interfaces for object-oriented systems</a> </p> <p>Anyway... getting to the actual point, finally!</p> <p><strong>1.</strong> Can anyone recommend any books that discuss this in detail? I don't want an MVC book; I'm not sold on MVC. I want a book that discusses OO / UI, the potential issues, potential solutuions etc.. (maybe including MVC) Arthur Riel's <a href="http://rads.stackoverflow.com/amzn/click/020163385X" rel="nofollow noreferrer">Object-Oriented Design Heuristics</a></p> <p>touches on it (and is an excellent book as well!), but I want something that goes into more detail.</p> <p><strong>2.</strong> Can anyone put forward an argument that is as well-explained as Allen Holub's JavaWorld article that explains why MVC is a good idea? </p> <p>Many thanks for anyone who can help me reach a conclusion on this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload