A
A
Alexander Rublev2019-10-29 21:08:40
Design patterns
Alexander Rublev, 2019-10-29 21:08:40

Models in MVC/MVP patterns?

Hello everyone, I'm trying to figure out the MVC and MVP patterns.
I am writing a large desktop application (more precisely, I am going to rewrite).
I seem to understand these patterns, but I want to understand one point.
As far as I understand, a model is an object of a class that provides data and logic for the view.
For example, we work with workers in an enterprise:
There is a WorkerModel class that describes a worker and methods for working with him.
But what if I need to display a list of all workers, and for example, count how many laid off, or something else. As I understand it, I need to create a new model of the WorkerListModel type, which will already have methods for working with a list of workers, and for example, counting laid off, and so Further?
I write in simple language, so do not swear.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-10-30
@Maksclub

But what if I need to display a list of all workers,

A pattern such as Repository will help you.
For each model, a certain class is created that encapsulates the details of how and with what help it does it (via SQL or from memory, via ORM or without) and gives only collections / arrays of ready-made objects you need )
something like this:
class WorkerRepository(object):
     def __init__(self, DBSession)

     def get_dismissed_count(self, count)

     def get_all(self)

Example: jordifierro.com/django-clean-architecture
Here are examples in Django, but in fact the architecture is taken from a book by Robert Martin and applies to the architecture of desktop applications, especially look at how the repositories are organized there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question