Hot answers tagged

65 votes

Is it bad practice that a controller calls a repository instead of a service?

No, think of it this way: a repository is a service (also). If the entities you retrieve through the repository handle most of the business logic there is no need for other services. Just having the ...
Joppe's user avatar
  • 4,566
65 votes

What are the improvements of MVP over MVC?

MVC is conceptually elegant: user input is handled by the controller the controller updates the model the model updates the view/user interface +---+ +----| V |<----+ user | +...
amon's user avatar
  • 133k
49 votes
Accepted

Why does everyone put controllers in one folder and views in another?

I'd like to say it's cargo cult programming, but there are technical reasons for this structure. Asp.Net MVC took a convention over configuration approach to nearly everything. By default, the Razor ...
RubberDuck's user avatar
  • 8,921
32 votes
Accepted

MVC and RESTful API service

MVC is a paradigm from the Smalltalk world concerned with how object orientated systems could have UIs. Early web frameworks took the general idea (separate out business logic, controlling logic and ...
Cormac Mulhall's user avatar
28 votes

How do you separate view from logic in a Winform application?

MVVM(Model-View-ViewModel) Pattern can be used in the Winforms Model public class Person { public string FirstName {get; set;} public string LastName {get; set;} } ViewModel public class ...
Fabio's user avatar
  • 3,086
22 votes
Accepted

What did the reviewer refer to in this code review?

Tackling each of these at a time: Regarding the Project Structure This one can be subjective at the best of times, but projects are typically structured by logically dividing your code into sub-...
Ben Cottrell's user avatar
  • 11.7k
18 votes
Accepted

Can domain models in the database be a sustainable solution?

You're describing an Inner Platform. The problem with inner platforms is that you reinvent all of the mechanisms of a platform or technology (in this case, a relational database) that have been honed ...
Robert Harvey's user avatar
18 votes
Accepted

Patterns are not building blocks – so I shouldn't build an app on MVC/MVP patterns?

If I understand correctly, this means not to use a design pattern until it makes sense to do so, correct? Yes. Don't start off saying you're going to use the Strategy Pattern, wait until you ...
Ixrec's user avatar
  • 27.7k
17 votes

Testing: deterministic or non-deterministic?

Both. Deterministic and nondeterministic tests have different use cases and different values to your suite. Generally nondeterministic can't provide the same precision as deterministic testing, which ...
Hovercouch's user avatar
15 votes

Is it bad practice that a controller calls a repository instead of a service?

It is not bad practice for a controller to call a repository directly. A "service" is just another tool, so use it where it makes sense. NikolaiDante commented: ... Pick the right pattern for the ...
Greg Burghardt's user avatar
12 votes
Accepted

Do common MVC frameworks violate the LSP and is there a MVC framework which does not?

Ignoring the philosophical question of "to violate or not" (that sounds bad...), you omitted the sentence immediately prior to your quote: The intuitive idea of a subtype is one whose objects ...
enderland's user avatar
  • 12.1k
12 votes
Accepted

Who communicates with the database in MVC/MVP?

I've seen it done two ways. The first way is to do everything using CRUD methods. That's essentially the way you are describing: Create, Read, Update and Delete. Most Object-Relational Mappers (ORM'...
Robert Harvey's user avatar
12 votes

Is Model a better place to set HTTP status code?

The Controller is responsible for handling the HTTP request and knowing what to do. Setting the HTTP status code in the Controller is the right place to do this. There are a few problems in doing it ...
Greg Burghardt's user avatar
12 votes
Accepted

How to architecture a realtime-heavy websockets-based web application?

How to structure the data that is sent from the server to the user? Use the messaging pattern. Well, you're already using a messaging protocol, but I mean structure the changes as messages... ...
Kasey Speakman's user avatar
12 votes
Accepted

Proper design to avoid the use of dynamic_cast?

I would like to expand on Emerson Cardoso's "other suggestion" because I believe it to be the correct approach in the general case - though you may of course find other solutions better suited to any ...
doubleYou's user avatar
  • 2,767
11 votes

MVC and RESTful API service

View is a layer responsible for displaying information which may be interpreted by a user/client of your application (it does not say the user has to be an actual person). JSON is completely valid ...
Andy's user avatar
  • 10.3k
10 votes
Accepted

Should the View not perform validation?

I don't think there is a single place where you can say all the validation should go. This is because we have a few different competing programming strategies working together in a standard asp.net ...
Ewan's user avatar
  • 72.3k
10 votes

Why does everyone put controllers in one folder and views in another?

Whatever the reason, this is poor practise. It is very anti-OO because packages or folders (whatever you want to call them), should have weak inter-dependencies. Classes (or files) inside them should ...
Oliver Watkins's user avatar
10 votes
Accepted

The right place for "app logic" in MVVM context

In MVVM, the business logic is built into the Model. The ViewModel is there to bridge between the View and the Model, so it's logic only pertains to driving the display and updating the model from ...
Berin Loritsch's user avatar
9 votes
Accepted

Never using Models, only ViewModels

Would my Data project be considered the "Model" for my application? Yes, that's exactly what Model is supposed to be. Is this a right approach I believe it is. or could there be potential ...
Euphoric's user avatar
  • 37k
9 votes
Accepted

Where to put User Interface/Domain Model manipulation logic (transferring data from the view to Domain Model)

Bear in mind that the Model View Controller (MVC) principal has been hijacked and bastardized by the web development world. In a real MVC application the model view and controller are largely ...
squarewav's user avatar
  • 206
9 votes
Accepted

MVC: Display requested content via the View

Model View Controller is one of the oldest if not first design patterns. It was created at a time when few people understood any proper way for objects to interact. Consequently the only common ...
candied_orange's user avatar
9 votes
Accepted

Storing directly in the model

When you use void updateTitle(String str) { this.title = str this.store.update(this); this.notifier.notifyAboutChange(this); } you are grouping two operations into one -- updating the ...
R Sahu's user avatar
  • 1,986
9 votes
Accepted

What alternative name to give to controllers?

The point about avoiding "smurf naming" is not to think of synonyms for "smurf", but to not use the term. So the thinking goes that if you have a user controller in a folder called Controllers, then ...
David Arno's user avatar
  • 39.1k
9 votes

Do we need Models if we are using ViewModels?

Having a Model and a ViewModel promotes separation of concerns by allowing your Model to work independently from the rest of your system. Have a look at the following architecture: {Database} --> ...
Robert Harvey's user avatar
8 votes
Accepted

MVC - Do I create 'joint' layers when dealing with multiple models?

In the MVC design pattern, the Controller part is responsible for translating user actions into modifications of the various Model classes that are involved in a piece of functionality. There is no ...
Bart van Ingen Schenau's user avatar
8 votes

Why does everyone put controllers in one folder and views in another?

To answer your 'Why everyone...?' question: Here are some potential reasons, although I'm not entirely sure which combination of them is a real cause, since it is actually a subjective question To ...
Bishoy's user avatar
  • 271
8 votes
Accepted

How can I move from Web Forms to ASP .NET MVC 5?

You're going to have to embrace ASP.NET MVC in its own right. There is no server code-behind. There are no drag-and-drop widgets, no plugins, and no leaky page life-cycle. There is no almost-wysiwyg:...
Robert Harvey's user avatar
8 votes
Accepted

Am I breaking SRP when I inject Factory pattern with Repository layer?

While in general injecting something is not bad and does not automatically result into breaking the SRP (nor it does in your case - you have one class which only fetches data and another constructing ...
Andy's user avatar
  • 10.3k

Only top scored, non community-wiki answers of a minimum length are eligible