Object class or class objects?

    When I got a new job, I came up with a new question for an interview. I want to ask him for you too.

    Let us have a specific machine. SPECIFIC! Not a type or a class of machines, but a particular machine that I point to with my index finger. The owner of this car claims that his car consists of many components, including wheels. He says his car has five wheels (one spare). I note right away 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 the fact that the car consists of a class of wheels?




    Comments on the question:
    • By a class of wheels we mean a lot of objects. Not what is meant by this term in OOP (type description, object model, description of common features), no. We understand just a set of some objects. The fact that one of the objects has a square shape does not bother us. The owner said that these are wheels, which means wheels.
    • Consisting of does not mean that it consists only of. A machine consists of a lot of what. We will not list everything. But also consists of wheels. Many people think that consists of requiring an enumeration of all structural elements, but this is not so.
    • Consists of - means that the machine and that with which it is connected by a “consists of” connection are connected by a connection. Let me remind you that the term “consists of” has several meanings:
    1. Composition:
      1. A gas is made up of molecules, which means the relationship between a gas and a class of molecules.
      2. The puzzle consists of five of these elements. Consists of in this case implies five connections "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 “composition” connections between an apple tree and each of the listed objects.
    2. Aggregation: A heap of sand consists of two heaps.
    3. Specialization: the class of apple trees consists of varieties of apple trees. This is the relationship between the multitude and its subset.
    4. Classification: a machine class consists of machines. This is the relationship between the class of objects and the objects of the class.

    Let us 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 in only two ways: “a car consists of a class of wheels” or “a car consists of objects of a class of“ wheels ”.

    Both of these options determine the relationship of the composition. In philosophy, it is believed that the sum of the parts cannot be whole. This view is called holistic. Those who profess the opposite are called reductionists. In modeling a subject area, we profess the principle of holism and therefore affirm that a machine is not the sum of its components. And so we associate a machine with any of its components by a composition link.

    Once again I repeat the question: what does the machine consist of? Out of class wheels? Or from class wheels?

    If we ask this question to programmers, then they enter into a stupor. There are no models in OOP that link objects and classes. Programmers have either class diagrams or interaction diagrams. But for classes and objects to be on the same diagram - this is not in UML. Therefore, there is a hitch in the reasoning. Further, I have to remind once again that under the class the whole world (except programmers) understands many objects. And I have to remind you that a class in OOP is not a class in the real world. If the listener understands this, then he goes on 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 searches 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 anyway I ask the seditious question from the point of view of OOP: can a machine, and not a class of machines, be connected with a class of wheels and not with class wheels? The show is provided.

    So the answer


    We can say that a machine consists of a class of wheels, as an engine consists of a class of bolts, like a stool consists of a class of molecules. However, we cannot say exactly how the machine 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 connection between the machine and the class wheels. 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 the given wheel, for example, “right front”. It is clear that such relations also form a class of relations consisting of five elements. Then we say: a machine consists of wheels (meaning 5 links), an engine consists of bolts (meaning 100 links) and a stool consists of molecules (meaning a lot of links). 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 machine. 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 maintain knowledge of 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 connect each number with the machine and we connect the attribute of the location of the wheel with a number. So in this case, we simply form the relationship between each wheel and the machine through the attribute value (number).
    So, there are two ways to build an object structure. 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 complicate the situation. Let now we have a class of cars. Each car has a class of wheels, or class wheels. Let it be true that any car consists of 5 wheels. Let's see what objects we already have:
    1. Objects of a class of cars (cars). The number of such objects N.
    2. Class cars. The power of this set N.
    3. Wheel class objects (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 one car. The number of such objects N.
    6. The class of wheel classes belonging to one machine. The power of this set N.
    7. Connections between cars and wheels. The number of such objects is 5 * N.
    8. A class of connections between cars and wheels. The power of this set is 5 * N.
    9. The relationship between cars and classes of wheels belonging to one machine. The number of such objects N.
    10. A class of connections between machines and classes of wheels belonging to one machine. The power of this set N.
    11. We can add new links:
    12. A class of cars can be associated with a class of wheels. The number of such links is 1.
    13. A class of machines can be associated with a class of classes of wheels belonging to one machine. The number of such links is 1.
    14. A class of wheels can be associated with class wheels. The number of such bonds is 5 * N.

    Every object and every connection has semantic meaning. For example, a machine class denotes an object consisting of many machines. The class of wheel classes belonging to one machine indicates the presence of sets of wheels, each of which (sets) belongs to one machine. The connection between the class of cars and the class of wheels denotes the thesis: for the manufacture of a batch of machines you need a batch of wheels. Etc. 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 relationships yourself by using this analogy. True, some connections will be very strange in terms of the logic of the layman. But this does not exclude their impossibility.

    Also popular now: