We write an application for acceptance of various nomenclature (equipment) from suppliers (monitors, printers, etc. office equipment). Acceptance is carried out on the basis of a document in which there is an N-th number of lines. Each line is a separate nomenclature with the name, code, price, number, and so on. For each item of the nomenclature is assigned one inventory number. Now to describe this, we use the following classes:
// ΠΡΠΎΡ ΠΊΠ»Π°ΡΡ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ Π΄ΠΎΠΊΡΠΌΠ΅Π½Ρ class Doc { String docNum; // ΠΠΎΠΌΠ΅Ρ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° List<DocRow> rows; // Π‘ΡΡΠΎΠΊΠΈ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° } // ΠΡΠΎΡ ΠΊΠ»Π°ΡΡ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ ΡΡΡΠΎΠΊΡ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° class DocRow { Nomen nomen; // ΠΠΎΠΌΠ΅Π½ΠΊΠ»Π°ΡΡΡΠ° int count; // ΠΠΎΠ»-Π²ΠΎ ΠΏΠΎ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΡ int price; // Π¦Π΅Π½Π° ΠΏΠΎ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΡ List<Invent> invents; // Π‘ΠΏΠΈΡΠΎΠΊ ΠΈΠ½Π²Π΅Π½ΡΠ°ΡΠ½ΡΡ
Π½ΠΎΠΌΠ΅ΡΠΎΠ² } // ΠΡΠΎΡ ΠΊΠ»Π°ΡΡ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ Π½ΠΎΠΌΠ΅Π½ΠΊΠ»Π°ΡΡΡΡ class Nomen { String code; // ΠΠΎΠ΄ String name; // ΠΠ°ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π½ΠΈΠ΅ } // ΠΡΠΎΡ ΠΊΠ»Π°ΡΡ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ ΠΈΠ½Π²Π΅Π½ΡΠ°ΡΠ½ΡΠΉ Π½ΠΎΠΌΠ΅Ρ class Invent { Nomen nomen; // ΠΠΎΠΌΠ΅Π½ΠΊΠ»Π°ΡΡΡΠ° String barcode; // ΠΠ΅Π½Π΅ΡΠΈΡΡΠ΅ΠΌΡΠΉ ΡΡΡΠΈΡ
-ΠΊΠΎΠ΄ } As a result, the nesting of classes is as follows:
It can be seen that the class Nomen is on several levels and, as it were, is dragged below. The question is, how much is right to do that? What are the basic rules?
We did this because copies of links to an instance of the Nomen class at different levels are very convenient. For example, we have a method for printing a packet of inventory numbers print(List<Invent> invents) on a printer. When printing the inventory number, Invent.barcode needs to display the same name. Thanks to access to Invent.Nomen.name, we can do it without any problems, without adding additional logic to find this name.
The Invent class, as it were, can communicate its bar code and type of nomenclature, which makes it sufficiently self-sufficient. Moreover, in the future, we can use the Invent class in general outside the DocRow class , and then we definitely need to understand to which type of item the inventory number belongs to.
What will prompt colleagues with years of experience?
Thank.
