Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it a big crime to collect Controller and View in one class?

Why this question:
From my perspective, Controller and View by nature is mostly given through a "Framework" as WinForm, WPF, browser frontend... and bound already there very strongly.

What is a strong argument to still separate Controller and View?

A note which - I think - is important: For me all logic needs to be implemented in Model. I would never implement logic in Controller.

I don't expect a final answer. More I will be happy to read some pros and cons and sorry if it is maybe a too General quest

Thank you very much in advance
Posted

1 solution

Having then in one class would be weird, to say the least. However, formally, MVC as an architectural patterns, which is not really concerned with classes. It is more conceptual and could be suited to many different programming models, even those without classes (take JavaScript, for example). Therefore, again, quite formally and not practically, those two parts of architecture could be collected in one class, but then it could be a big misuse of classes, forget practical reasons. If you want to practice this approach, one anti-pattern you could use would be, in particular, God Object:
https://en.wikipedia.org/wiki/God_object[^].

So, I have no clue how such idea could even visit you mind. :-)

As to the location of the "logic", this is somewhat fuzzy concept, so it depends on what you call "logic". I would not even think in such terms. The controller can send commands to a model and to a view, thus providing some kind of, presumably, loose coupling between them. Such coupling also has some logic behind, or something one could rightfully call "logic". But still, it's the model which "directly manages the data, logic and rules of the application":
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller[^],
https://en.wikipedia.org/wiki/Loose_coupling[^],
and, after all, https://en.wikipedia.org/wiki/Logic[^] :-).

—SA
 
Share this answer
 
v2
Comments
[no name] 11-Sep-15 14:43pm    
First of all, thank you very much for your Response, and a 5 for it.

But; please I'm sure you understand what I'm asked, but you nail me on details like "class", "logic". No, I don't like to define all the terms in EBNF before I ask a question ;)

<blockquote class="quote"><div class="op">Quote:</div>Having them in one class would be weird, to say the least</blockquote>Ok, I used the term "class", my meaning is "coneptional collected". Sorry I can not take _all_ the technical solutions into acount in a question....

<blockquote class="quote">As to the location of the "logic", sorry but https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller[^] is something very weak...ok, but at least not that wrong like the german version ;)

Never, realy never, I would give the controller a chance to be a part of my BL. Why? Because my Model should work also without the help of a Controller.
</blockquote>

[Edit]
Uuups, formating is not that transparent here
[/Edit]
Sergey Alexandrovich Kryukov 11-Sep-15 16:48pm    
All right. You are welcome. No problem with telling the detail of your question; this is a pretty much free discussion.
Generally, I consider the whole idea of BL, "business logic" quite questionable or at least fuzzy. It's a kind of an ugly consequence of the fact that the whole software development was strongly distracted from science and technology to business, often overly trivial. I am not doing any business-related software, so, should I also call part of our logic "business logic"? But, frankly, just "logic" is not much better or better defined. I would not use such notions at all, by all the reasons I tried to explain. In practice, the considerations should consider more essential matter, focused on more concrete actions described as "logic".
—SA
[no name] 12-Sep-15 6:40am    
In your comment you wrote "logic" is not a good term, but what is a better one? Is it "behaviour"? For me "logic" is ok and more or less precise...to be clear the word "Business" is not needed.

In your answer: Yes there is also some logic behind interaction, but this is not what I mean when I refer to logic, this are "only" minor things and given by the Model (Controller and View get the info "what is possible/availabel" from the Model). For me, logic is _exactly_ what you mentioned at the end:
"it's the model which "directly manages the data, logic and rules of the application""


I accepted your Response. Thank you for your time.
Sergey Alexandrovich Kryukov 13-Sep-15 12:02pm    
You are very welcome.
I really don't know what to say about the terminology, would be in great doubt if I put forward some pattern of
this kind... :-)
Yes, I think I understood your view on the role of controller and assume it's reasonable.

Here is what I think: the logic you put in the model reflects the application semantic. The controller's logic (in the sense I discussed) may or may not reflect some part of application semantic. Is it good if it does? Hardly. It's desirable that the controller code was abstracted from the application semantic, that way, it could be — just one particular aspect — more easily reused for some other applications. But it's even more desirable to prevent application semantic from spreading between model and controller (or something else). I think this is what you require, according to you "never, really never, I would give the controller a chance to be a part of my BL" view. Therefore, the application semantic should be modeled solely in the model part of the architecture and be comprehensive enough for that purpose.

Probably, in a pinch, the authors of the literature in the topic assumed that semantic is some "business" and kept using the term "business logic". I think the essence of things is the decomposition of every solution (in general sense of this word, not in the sense of VS file :-) into the parts according the the levels of abstractions. Say, you can have abstract and universal layer (from the standpoint of computing) which is semantic-agnostic, relative to the application semantic. In you mix a part of application semantic in it, it cannot be reasonable reused (but such reuse may or may not be required). The semantic-aware layers can also be further stratified, because, say, semantic may reflect application field, which should not be specific to a particular organization (say, stakeholders ordering the software). And so on... Every layer has something which can be called "logic", but the point is not to mix the part of knowledge of different degree of abstraction between them. The key point here is: where the knowledge on each subject comes from?

—SA
[no name] 13-Sep-15 12:13pm    
Wow, thank you very much for this, I have still to process all this in Details first. Sorry I can't vote more than 5.
Bruno

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900