A Composite is a template that is useful at any time when you may need to selectively process a group of objects that are part of a hierarchy as “identical” when they are actually different. Commonly used examples speak the same in terms of leaf and node processing, but the template can also be extended to heterogeneous lists.
For example, consider visiting a doctor. When you go to the doctor, different things happen, you usually see a nurse or assistant, they take your temperature, etc. Then the doctor performs an exam and makes a diagnosis. Then the doctor may do some treatment, but often the nurse comes back to finish. During the visit, various events are held. You have observations, such as weight and temperature. But the laboratory, for example, will be a different facility, because it often requires a sample, which can then be sent and requires that the results be recorded later.
So, we have software that allows us to record all this, and it usually creates some hierarchy with nodes such as:
Encounter:
Preexam
Exam
Treatment
and under each of these nodes you will have many records, such as diagnostics, observation, laboratory procedure, diagnostics, injection, etc.
This is good and good, and you get a structured, albeit very complex, hierarchical record of the meeting.
Now suppose you need to create billing. Suddenly you are faced with a completely different demand. Your medical record was necessary to create a very accurate picture of the meeting. When billing, although you don’t care who did what or in what order, you don’t really care what happens outside of the billing code. You just need one list of paid actions, i.e. codes.
This information is not only embedded in the record, but this record is very complex, because it contains a large number of different objects. It also varies in a hierarchical structure - if you have a nail in your head, they can skip any preliminary exam or exam on this subject and switch to treatment. If you go in to remove stitches, there may not be an exam or exam. The annual physical treatment does not have. etc. It is very difficult to list this type of object graph.
A composite template solves all this. You define a common interface or base class for all objects. Let me call him "CareEntry." CareEntry has the BillingCode property. Now your Encounter may seem like a simple container that contains only CareEntry objects. Now your billing service will simply list everything without worrying about whether there is something node (PreExam, Exam) compared to the sheet (weight temperature) or that the node object is located (PreExam exam, etc.) Or what is the actual type of object (laboratory, injection, etc.). Everything also applies to CareEntry and is processed evenly. You simply list all CareEntry objects in Encounter and collect each one that has a zero billing code, and you're done. It is so simple.