educative.io

Realtion between Order and Waiter class

How come Order class has a waiter as member ? and i am sure Waiter class( missing from snippet) will have List of orders. In class diagram the relation between Order and waiter class is association. Please explain how.

Hi @Vishal_Bharti,

Thanks for reaching out.

Short answer, Association is established in the code as reference properties (class attributes), as in the case of Waiter and Order. People confuses association with ‘Dependency’ which is realized in the code through a method parameter or a return attribute from a method.

For detailed answer take a look here: Association vs Aggregation vs Composition in the code.

The relationship between Waiter and Order could be a two-way association, if we have a requirement like ‘The system should generate a report of all the orders a waiter has created’. In this case we have to have a list of orders in the Waiter class.

Hope this clarifies your question.