Author Topic: Control Classes  (Read 772 times)

zyx

  • EA User
  • **
  • Posts: 74
  • Karma: +1/-1
    • View Profile
Control Classes
« on: December 26, 2016, 05:37:22 pm »
Dear all,

   As always I apologize for my bad english ...

   I learned that in the MVC standard the logical business methods must be placed in the control classes. Well I had a model where I was putting these methods into entity classes and I tried to create some control classes and I transferred the methods to them, but I realized that some methods will be repeated in more than one control class (I have created a control class for each use case), for example it is necessary to validate the password in more than one process. What should I do in this case? I think it's wrong to repeat the same method in more than one control class ...

Helmut Ortmann

  • EA User
  • **
  • Posts: 884
  • Karma: +37/-1
    • View Profile
Re: Control Classes
« Reply #1 on: December 28, 2016, 01:59:49 am »
Hi,

in my point of view be careful with mixing different concepts.

The MVC concept is used to build graphical user interfaces. The logic how to calculate an item to visualize is usually part of the M as Model. Often this is called the business logic. Usually, the logic how to control the graphical user interface is part of the C as Controller.

There is another concept like (not GUI related):
- Entity
- Controller
- Boundary

If you search the internet, you'll find a lot of opinions, and you carefully have to look if the solution prescribed fits your problem.

Regarding password validation:
In my opinion, password validation is part of the business logic. Therefore part of the model. Repeating code, Methods is almost never a good solution.

By the way: Don't apologize, just write. Most of us aren't native English speaker. If you want to improve your English you may use tools like Grammarly.

Kind regards,

Helmut

 


Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

zyx

  • EA User
  • **
  • Posts: 74
  • Karma: +1/-1
    • View Profile
Re: Control Classes
« Reply #2 on: December 28, 2016, 02:38:19 am »
Hello,

Thank you for the help. I confess I am now confused with the MVC pattern. I used to put most of the business methods in the entities classes, but I read some texts that say it is not the correct way to use this pattern ...

    I have an example, in a system for a bankary institution I can have common accounts and special accounts (the difference is that in the common accounts you can only withdraw the money you have in the account, while in the specials accounts you can withdraw some more defined in the limit of the account).

    Well in the model I had a CommonAccount class entity where I had the openAccount and withdrawMoney methods and I specialized this class in the SpecialAccount class, where I have override the two methods.

    I had a control class but I only used it to control the events in the boundary. Now, trying to apply more correctly the MVC pattern. I transferred the openAccount method to a control class linked to the process of open an account and I removed the openAccount methods from the entities classes, also because these methods were practically constructor methods. My thinking was that the controller could decide where to call the builder according to the user settings in the boundary.

    But I did not do the same with the withDraws methods, since I thought it was more correct to keep them in the entities. So the controller linked to the withdrawal process does not have a business method ... But I'm not sure if I did it right ...