Observer pattern, how to link it with order queue in class diagram? - class

So I am working on this class diagram, I do get the idea that we need to implement observer pattern with order and customer class, however I couldn't understand what is the best possible way to maintain a relation between order queue ,staff and orders.
Original Question
A simple web application that allows customer to place orders select one or multiple items. As soon as the customer proceeds and confirms the order, The order get enlisted in the order Queue. Customer gets a confirmation for the order that he/she has place and mean while staff also gets notified for the new order via GUI of system.
The Class Diagram that I have so far

You have different observers i-e Customer and Staff member. So you will be having Staff and Customer as subclass of Observer.
Subject is Order. Whenever an order is placed/updated, you go through list of observers and notify them. So your diagram is correct where Order is subclass of Subject.
The orderItem can be of different type. You should inherit different subclasses from parent "Item" class.(You are currently inheriting items from Gift Item".
There should be an aggregation relationship between "Item" and subject.

Related

How to decide whether a method should belong to which class?

I have 3 classes:
product
product_list
and customer
The product_list class has an array list, which stores product objects.
If I have a viewProduct method, it should belong to customer class or product_list class?
With my own concept, a viewProduct method should belong to customer class, because customer views products. But in code-wise, how a method in customer class gets data from product_list class?
A class is a data structure, bound together with the algorithms working on it.
Thus, if you decide where to put a method, the rule of thumb is this: select the class, on whose data structures it works the most. If you do it well, it should not even access the data members of other classes directly, only their methods.
Also from the name of the method is it visible, that you are right, that viewProduct should belong to customer: if it would belong to a product, then the viewProduct name would be redundant. Then a view name would be better.
You example does not say anything, how customers relate to specific products. For example, if you would develop a webshop, then the customers would likely choose a product from a list which your controllers generated for them.
Your specification lacks the mechanism, how customers relate to products. Think on it, and you will know the answer.

Class diagram's entity attributes inquiry

I have a scenario about a customer purchasing a stock from a company and calculating branch sales. So I made a class diagram of customer, purchase and branch sales but I am not sure what to put in the branch sales entity as this branch sales should indicate total sales done for each branch.
Here my diagram:
Should the branch sales includes purch_totalprice, purch_stock, and purch_stockquantity too, like in purchase entity?
The diagram looks more like an entity/relationship diagram for database tables than like an UML class diagram:
In an UML class diagram, you would not use a dotted line to separate the unique identifier form the other properties, but you would use a separator to show operations (i.e. methods or functions).
In an ER diagram, this practice is less unusual althoug not common either.
This being said, whatever the modelling language, this diagram:
doesn't show what the Customer is purchasing. stock is too ambiguous: is it a material that you have in an inventory? Is this a stock-exchange stock (a share in a company)? Whatever the answer, it would be nice to show this as an own class/entity (I'll use Product hereafter).
doesn't show any class/entity that is identified with a branch_id. I'd suggest to add an entity called Branch
doesn't show the associations/relations. You should have at least Customer--Purchase, Purchase--Product, and Purchase---Branch, nor their multiplicity/cardinality.
If you have all these information in your model, the "branch sales" are in fact a data extract of Purchase and not a distinct entity: the purchase of the customer being the sales for the branch. For your diagram:
If you're on a class model, you'd add a getSalesDetails() function: this function would return the list of all the relevant Purchase objects for that branch. You could also add a getTotalSales() that would make do a total of the relevant sales. Perhap's taking into account a date of the purchase?
If you're in an ER model, you would know how to find this data thanks to the association between branch and purchase (you can make it clear by labelling the relation Branch--Purchase as makes sales. But you could also show a separate table with the relevant data duplicated, if you want to document your physical model and intend to implement this in your database (either with redundant data ,not recommended, or with a view)
Last important remark regarding classes:
If your diagram should be an UML class diagram, but you want to show the details of your database model, you may put «table» above every entity.
But if you do not intend to document classes, i.e. the classes would stay without operations (i.e. class behavior) there's really something missing - it's like an anemic domain model (not forbident, but far from ideal).

Association class attributes in Domain Model Class Diagram

Hi, I have recently started to learn system analysis and design and am having some trouble understanding domain model class diagram (DMCD) association class.
As per image, when drawing the DMCD, I'd like to understand if an association class is allowed to contain attributes of the classes it derives from. The Invoice needs to contain the attributes apptNo and svcName.
Association class inquiry image:
Do I include the attributes as shown in the image?
Or do I assume that the Invoice would already have these attributes because it is derived from Appointment and Service and that it is not necessary to include them as they can be referred back to the keys apptNo and svcID?
I am confused about the concept. How should I present the association class?
Can someone please provide some guidance?
Thank you.
As already pointed out by Geert Bellekens in his comment above, you don't repeat any of the attributes of the classes involved in an association class in the association class. You only include attributes that specifically characterize the links classified by the association class.
In your example, you should only include attributes that are specific for Invoice links, such as invNo, invDate and totalPrice.
This rule holds independently of the kind of class diagram (domain/design/implementation model).
However, your model is only good for invoices refering to one appointment and one service. It does not account for invoices concerning one appointment, no matter how many services it includes. In a model for this business logic, Invoice would no longer be an association class, but an ordinary class associated with Appointment. This would allow it to access each service included in an appointment and turn it into an invoice line.
To make it short:
is (sort of; please read the comments below) an alternative notation for
which means that Class3 already has associations to both Class1 and Class2. So there's no point in adding attributes of the latter in the association class. If you're on a DB level you eventually introduce redundancy for performance reason at the cost of violating the principle of single source of truth. But that's another story.
It depends.
A domain model class diagram models the concepts found in the domain, i.e. the part of the real world relevant for your project. In the classes, you only include attributes that are indicated by domain experts or by other sources describing the domain.
I will assume that a domain expert knows what an appointment number and a service name are. If these were just technical data, they should not be attributes of Appointment and Service in the first place. To determine whether these attributes should also be included in Invoice, you need to ask domain experts what they think. Does an invoice always include an appointment number and a service name? Only if the domain expert says "Yes", I would model them as attributes of Invoice.
(To double check, you could ask "Is it also valid to say that the appointment number is not part of the invoice, but that the invoice is somehow associated with an appointment having a particular appointment number?")
Maybe the domain expert says an invoice does not contain the appointment number or the service name, because the corresponding Appointment and Service are always associated to the Invoice as attachments or hyperlinks or otherwise. In that case, the fact that Invoice is an association class on the association between Appointment and Service is enough. You don't have to include attributes of these classes in Invoice. These will probably be added later, when the domain model class diagram is turned into a system model class diagram or database model class diagram.

Entity Framework multi-inheritance?

I have an abstract base class Contact that has two subclasses: Person and Company.
I want to have a Customer, Vendor or other types that can be either a Company or a Person (all sharing the same primary key ContactId).
My question is if it's possible to inherit all these types from Contact? If the answer is no, is there another option of utilizing the Contact property from the PK? What's the recommended design for this scenario?
Note that I want an Employee/Customer etc. to also be able to be a User.
How would you achieve that in C#? That is the first question you must answer yourselves because .NET doesn't support multi-inheritance so you cannot have single Customer class derived from Person or / and Company - you need separate Customer class derived from Person and another Customer class derived from Company but every time you see this you should know that you are doing something wrong. Also if you in the future find that you need to have Contact which is both Employee and Customer you will be ready to delete whole your application because with inheritance there will be no way to achieve that. Changing Contact from Customer to Employee will be possible only with direct SQL because EF doesn't allow that.
Inheritance is not solution for your problem - you must use composition (relations).

Domain Modeling or class diagram for car dealership

I am trying to draw a domain model or class diagram in UML for car dealership. I am stuck with how to present test drive in the model. One way is to have appointment class and then test-drive as sub class. A dealer also offers after-sale vehicle service so i could have appointment/booking class as super class and then vehicle service and test-drive as two sub classes.
Another way is to have the customer class have a direct relationship with test drive class and vehicle service class under appointment class.
A dealer also sells new and used cars and their parts.
A dealer also offers finance for car sale.
Would testdrive class have relationship with vehicle class or there is separate class for display and testdrive class?
Another question is how do I show potential customers and their inquiries about sale and service in the model. A dealer wants to save details of potential customers if they allow for marketing purposes. Shall I have two classes: one for customers and one for potential customers or it can be achieved just by using an attribute in customer class?
You can really only distinguish the right decision by having a good set of use cases or expected behaviors of the model.
This will inform whether a particular sub-classing is really accurate.
I can see that an appointment might contain several test-drives, which are themselves linked to individual vehicles, So a test-drive itself is nothing more than a link from a customer to a vehicle which are linked to an appointment.
test-drive would contain the information relevant only to the test-drive:
reference to the customer - even this might be debatable to include
reference to the vehicle
length of test drive
location (perhaps the vehicle was driven at a different location than could be determined from the owning appointment)
customer temperature (hot or cold - i.e. did the customer seem enthusiastic)
comments
etc.
But what is not in the test-drive object is anything related to the appointment - since it is always contained in a collection - possibly as part of an appointment or some other event container. Now if the containers which can contain test-drives always include customer information, I might not even include the customer reference in the test-drive object - after all, it will be redundant.
It depends if test-drives can occur in non-appointment scenarios - perhaps at a "sales event" or an "open house" or something where appointments are not actually created in the use cases - or if test-drives for multiple customers will occur within a container.
The second part of your question has been forgotten (easily done when you ask two questions in one):
Another question is how do I show potential customers and their inquiries about sale and service in the model. A dealer wants to save details of potential customers if they allow for marketing purposes. Shall I have two classes: one for customers and one for potential customers or it can be achieved just by using an attribute in customer class?
I think your use case there is "A dealer wants to save details of potential customers if they allow for marketing purposes." and the simplest solution is to have a Mailing List collection which holds name and address of each potential customer.
I think you miss the point. The aim of the domain model is make famliiar you with the domain:
-- What kind of entities you have in yor domain?
-- If they are important for your system under desing,
what kind of properties they have, how they behave?
-- What kind of business rules they obey?
The rest is details. Think like a map maker. Record what there is.Create a simple map so you can not lost your way in that domain. Not try to invent.Abstract what exist in the domain: Not run behind the "fancy abstractions" you created yourself.
Domain model can be used as a source
for object oriented analysis/design.
But their aim is not to represent
software abstractions.