L
L
lipuha32022-03-05 14:52:02
C++ / C#
lipuha3, 2022-03-05 14:52:02

What should be included in the classes?

More precisely, what to write in certain classes. Let's say I have a console application for an online store. I created the class of the store itself (the products will be stored in it), I created the client class (the name of the client, money, etc. will be stored there).
And the user will accordingly buy these products. So, where to implement this purchase logic? In the client class, or in the store class, or even in the Programm(main) class? Sorry in advance for the stupid question. But for me, as a beginner, it is important to know this :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
freeExec, 2022-03-05
@lipuha3

From a technical point of view, this is not important at all. All OOP is about logical connections. If you think that it is the client who buys the product, then do the client method. If this store sells, let him have the method. Yes, you can even at the cash register, the main thing is that you understand what and how it was convenient for you.

V
Vasily Bannikov, 2022-03-05
@vabka

It doesn't matter where you implement it. You can even make a whole separate class to describe the buying process.
So do what is more logical and convenient for you personally.

G
Griboks, 2022-03-05
@Griboks

The purchase process is described in a separate class, which even has a separate name - a transaction. The client creates a transaction and sends it to the store, then the store confirms the transaction and returns the purchases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question