📜 ⬆️ ⬇️

Object class or class objects?

Getting a new job, I came up with a new question for the interview. I want to ask it to you.

Suppose we have a specific machine. SPECIFIC! Not the type and not the class of machines, Namely a particular machine, which I point with my index finger. The owner of this car claims that his car consists of many components, including the wheels. He says that his car consists of five wheels (one spare). I note immediately that the owner says: "consists of", and not "includes."

Question: listening to the owner of the car, what do we imagine: that the car consists of wheels of one class?
')


Or that the car consists of a class of wheels?




Comments on the question:
  1. Composition:
    1. A gas consists of molecules, which means a bond between a gas and a class of molecules.
    2. The puzzle consists of five of these elements. Consists of in this case implies five links "composition" between the puzzle and objects of the class "Elements".
    3. An apple tree consists of roots, a trunk and a crown - it means three connections “composition” between an apple tree and each of the listed objects.
  2. Aggregation: a heap of sand consists of two heaps.
  3. Specialization: class apple trees consists of varieties of apple trees. This is the connection between the set and its subset.
  4. Classification: A class of cars consists of machines. This is the connection between the class of objects and the objects of the class.

Remember for the future, these six different interpretations of the term "consists of".

However, in our case, the thesis “a car consists of wheels” can be interpreted only in two ways: “a car consists of a class of wheels” or “a car consists of objects of the class“ wheels ”.

Both of these options determine the relationship composition. In philosophy, it is believed that the sum of the parts can not be whole. This view is called holistic. Those who profess the opposite are called reductionists. In modeling the domain, we profess the principle of holism, and therefore we assert that the machine is not the sum of its components. And therefore, we associate the machine with any of its component connection composition.

I repeat the question: what is the car made of? From the class of wheels? Or from the wheels of the class?

If we ask this question to programmers, then they go into a stupor. In OOP, there are no models linking objects and classes. Programmers have either class diagrams or interaction diagrams. But to have both classes and objects on the same diagram, there is no such thing in UML. Therefore, there is a hitch in the reasoning. Then I have to remind once again that by class the whole world (except programmers) means sets of objects. And we have to remind you that a class in the PLO is not a class in the real world. If the listener understands this, then he proceeds to the task itself. If he does not understand, then he includes a series of questions under the general flag “Why do we need this?” Suppose that the listener understood both the question and the theses and began to reason. First, by inertia with OOP, the listener is looking for classes. And we do not have a class of cars, but there is only one car. The listener is trying to create a class with a single element, but this does not save, because I still ask a seditious question from the OOP point of view: can a car, and not a class of cars, be associated with a class of wheels, and not with wheels of a class? The show is provided.

So the answer


It can be said that a car consists of a class of wheels, like an engine consists of a class of bolts, like a stool consists of a class of molecules. At the same time, we cannot say exactly how the car consists of wheels, because in such rhetoric there are no coordinates that would describe the location of the wheels in the car. In this case, we usually say - the car consists of five wheels. Or - five carpenters participate in the work. Or - bricks are needed to build a house.

However, to describe the location of each of the wheels, you can use the link between the car and the wheels of the class. Then we get five “consists of” links that will connect the car and each of the wheels. We can attribute the attribute “location” to each such connection, and the value of this attribute will give us the location of this wheel, for example, “to the right in front”. It is clear that such relations also form a class of relations consisting of five elements. Then we say: the car consists of wheels, (meaning 5 connections), the engine consists of bolts (meaning 100 connections) and the stool consists of molecules, (meaning a lot of connections). For example, it will sound like this: the car consists of the following wheels: right front, right rear, left front, left rear, and spare.

There are those who use an ordered class of wheels to communicate with the car. Each number in this ordered class can be assigned a wheel location coordinate. And then they say that it is possible to associate a car with a class of wheels and at the same time preserve knowledge about the location of the wheels. This is not true. The fact is that we introduce another class of objects - numbers. We make the connection between the wheels and the numbers, we associate each number with the machine and associate the attribute of the location of the wheel with the number. So in this case we simply form the connections between each wheel and the car through the attribute value (number).
So, there are two ways to build an object. Say. That it consists of objects, or say that it consists of classes of objects. These two classes of statements are very similar to each other, but they must be distinguished.

Let's complicate the question


Now we complicate the situation. Suppose now we have a class of cars. Each car has a class of wheels, or wheels of classes. Let it be true that any car consists of 5 wheels. Let's see what objects we already have:
  1. Objects of class machines (cars). The number of such objects is N.
  2. Class of cars. The power of this set N.
  3. Objects of a class of wheels (wheels). The number of such objects is 5 * N.
  4. Wheel class. The power of this set is 5 * N.
  5. Classes of wheels belonging to the same car. The number of such objects is N.
  6. The class of wheel classes belonging to the same car. The power of this set N.
  7. Communication between cars and wheels. The number of such objects is 5 * N.
  8. The class of connections between cars and wheels. The power of this set is 5 * N.
  9. Links between cars and wheel classes belonging to the same car. The number of such objects is N.
  10. A class of connections between cars and wheel classes belonging to the same car. The power of this set N.
  11. We can add new links:
  12. The class of cars can be associated with the class of wheels. The number of such links is 1.
  13. A class of cars can be associated with a class of wheel classes belonging to one machine. The number of such links is 1.
  14. Wheel class can be associated with class wheels. The number of such bonds is 5 * N.

Every object and every connection has a semantic meaning. For example, a machine class denotes an object consisting of multiple machines. The class of wheel classes belonging to one car indicates the presence of sets of wheels, each of which (sets) belongs to one car. The connection between the class of cars and the class of wheels means the thesis: for the manufacture of a batch of machines a batch of wheels is needed. And so on. The ability to extract the necessary entities from the customer's story and model them correctly is the art of the analyst. You can continue to train in finding the semantics of the links on your own, according to the indicated analogy. True, some connections will be very strange in terms of the logic of the layman. But this does not exclude their impossibility.

Source: https://habr.com/ru/post/252467/


All Articles