U
U
Urukhayy2015-03-19 16:23:39
Programming
Urukhayy, 2015-03-19 16:23:39

When building systems in programming, is it worth it to group mini-programs?

For example, there is a program This program has a mini-program - for example, this mini-program can be a game of dominoes. For this game naturally we create some classes, methods, functions and variables with arrays.
So. Now we need to create a second game, also related to dominoes, but its variant is "goat". Thus the question emerges. Should we use common entities (arrays, classes, functions) for two different but similar games?
I will give an example of a common entity - a two-dimensional array (the first dimension is the game varieties, the second dimension is the slots for the bones of each game), which stores information about which domino bone is placed.
Or another example - in every game you need a "bank". You can create an array. The first cell will store information about the bank of the first game, the second cell - about the second.
And so, now why I asked the question. After all, if we do not combine similar mini-programs, then we have to copy very similar code, and in addition, we spend some time writing absolutely identical program entities (arrays, functions).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
god emperor, 2015-03-19
@God-emperor

Reading about late binding

G
GavriKos, 2015-03-19
@GavriKos

Copypasta is evil. Identical entities are no lesser evil. It is necessary to design the system in such a way that there is maximum reusability.
In your case, "a kind of domino" means changing only the rules of the game - the whole logic of the "hand", placing the dice on the table and other things is one. And here about arrays of "bank" - fairly did not understand. Why store both banks at the same time... But these are implementation details. Most likely you will have 1 CBank class that implements the logic of the bank of any game, and if you really need a bank for both games at runtime, then there will be an array of CBank instances. For example.

I
Igor Kalashnikov, 2015-03-19
@zo0m

Well, take everything to services (if possible), as it is now fashionable.
Or are you worried that having made dominoes, there will be copy-paste in the next similar project?
Well, this is normal, you will transfer some of the developments, improve them even more.
If you really want "kosher", then allocate all your common developments to the framework, and drag it from project to project. The difference will be that if you get confused enough, you can introduce new versions of the framework into old projects and they will work "cooler", but do not forget about regression and even if you have everything covered with tests everywhere (and this is not so ;)) there is still a chance that you will dump your old but stable application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question