How to make class diagrams using Composition?

Problem Statement:

A company has a number of employees, company also has several projects that it needs to work on. Each employee may be assigned to one or more projects, or may not be assigned to a project at all. A project must have at least one employee assigned, and may have any number of employees assigned. An employee's billing rate may vary by project and the company wishes to record the applicable billing rate for each employee when assigned to a particular project. At the end of each month, company mails a cheque to each employee who has worked on a project during that month. The cheque amount is based on billing rate and hours logged for each project assigned to the employee.

Before we move on to making class diagram for this particular problem, let's discuss what is composition relation and how we use it. For example we have ClassA and ClassB these classes will have composition relationship if ClassA object is composed of one or more ClassB objects and further in composition relationship if a ClassA object dies then all ClassB objects that this particular ClassA object has will die automatically. For instance a building class can have many room class objects but when the building object dies all the room objects it contains must die too. Composition has a solid black diamond symbol.

To make a class diagram we first look for particular nouns, in our problem statement we have company, employee and project. We can say that company has employees and company has projects further if a company project dies then all associated employee objects will die as well, so here we can use composition relation between company and employee and also between company and projects. But, there is something more in our class diagram ie. we have an association between Employee and Project classes and that is not an ordinary association rather this association has a function that checks the billing rate of each employee assigned to the job and also sends the cheque at the end of the month. So, we will be using association classes to show that function but if you don't know how association classes work I encourage you to read the tutorial I wrote on Association Classes (Part 1 and Part 2).

How to make class diagrams using Composition

Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at ko-fi.com

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.

Comments (write a comment):

how to draw e-r diagram if question asked employee's bo;;omg rate may be vary bye project and the company wishes to record the applicable billing rate for each employee when assigned to a particular project. Posted by: chetan k on Nov 25, 2012

It really helped a lot.
Thank you Posted by: Tony on Jan 04, 2022

leave a comment on tutorial leave a comment