0

Working on a Rails project at the moment, we're working on some mixin-type methods to provide descriptions for each of the models in the project.

There's a method called model_description which returns the description attribute of the instance of the model. I would have expected model_description to return a description of the class of the model - e.g. "A car is a type of vehicle commonly used for private transportation" rather than "this specific car is my favourite red car".

My question is, does the Model refer to the class or the instance? And what is the correct term for the other?

  • 1
    You've already used the right words. Model class. Model instance or model object. – candied_orange Apr 3 '19 at 13:51
  • I echo @candied_orange's statement. Is it class or instance? - Yes (yes "Model" refers to the class, and yes, "Model" refers to instances of those classes). – Greg Burghardt Apr 3 '19 at 15:48
3

In MVC, model is the instance, naturally. Model, view, and controller are objects that communicate with each other within a user interface.

However, the word model is ambiguous. It's often used to describe domain objects but this does not always match the MVC model.

For example, in the Smalltalk-80 browser (where MVC was invented and first used) the domain objects are the code elements (classes and methods) that are manipulated through the browser (the Smalltalk IDE before the name IDE was invented) and the model in MVC is an object that keeps the navigation state, such as currently selected class and method, and provides the views (separate panes of the browser) with appropriately selected information to display. Later developments led to composed MVC models where sub-aspects were encapsulated, enabling re-use of UI parts and a plug-in architecture for code tools.

So in your example, the Car class is certainly not the model, the instance might be, but that depends on your application. It might be just a domain object which is referenced by the MVC model of the application as part of its navigational state.

| improve this answer | |
  • No, I don't think so. The Car class is part of the model. You need an instance of it to make it work, but we don't normally distinguish between the two when we refer to the "model." Quite the opposite, in fact; you "model" a problem domain with classes, not instances. – Robert Harvey Apr 3 '19 at 14:51
0

The short answer to this question is, "it depends". There is no one fixed, precise definition of what MVC is.

So you'll find definitions that talk of the model in MVC being the "domain model", ie the entire set of business rules and data for the system. This might consist of a database, numerous entity classes, business rule classes, view models etc.

Yet you'll also find definitions that talk about individual classes, or instances of those classes, being models. There is no one model in these definitions, there are multiple ones.

In fact it's even possible to find definitions that claim both the overall system and those individual classes/objects are both the model.

My question is, does the Model refer to the class or the instance? ...

"Model" might refer to the class; it might refer to the object; it might refer to everything that isn't a view or controller; or it might refer to all of them.

... And what is the correct term for the other?

That one is easy: it's "model".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.