How to write reusable business logic in MVC models?

My problem is that we are trying to use the MVC framework (PHP). After a lot of discussion, I think that MVC is very good, but I lack the ability to write reusable model logic (applications). So, I'm not sure if we have the right approach to implementing our software in the framework of MVC.

First, I will describe the non-MVC, oo-approach that we are currently using.

For example, we are working on some browsers (yes, our profession). Imagine we have a game object. We often use this game object. We have several different pages where you can buy thoughts, so you need to make “money” on players with a “bank account” or imagine that you can fight with other players. We have several battle scenarios, and these scenarios occupy 2 or more game objects (this depends on the type of battle, i.e. clan battles, battles against the player, etc.).

So, we have several pages (and controllers) with different battle logic. But each of these controllers uses the player object to calculate all the attributes and objects that the player has, and what damage and protection the player will do.

So, how can we reuse logic in the player object in the case of the MVC model? it would be bad to duplicate all the necessary logic in different combat controllers and models.

I think the "gold-transaction" -logic would be a good example to give you more details. you need a transaction function in case of a battle, if you win against another player and throw part of your gold, you need a transaction function in case of buying some things, and you need a transaction function if you spend some gold for the guild of players ...

So, I would say that this is a bad approach to define all these functions in one player model! I can say that this player model would be very large (in fact, we have a problem that our player class is really huge - its god class)

, MVC?

+5
1

, , , - .

- , Player, , . , , , - , , - .

, , , , , . , , MVC, DRY , "" ... , , .

- , - , "" . , , / .

+1

All Articles