How to model attributes dependencies between different classes in UML object diagram? - uml

In scope of visualizing different parts of the system I would like to exactly show dependency between different attributes.
In my case the use case will be in UI where a User have to to choose Country and based on his selection values for Product have to be updated in corresponding dropdown eg.
Values for Class Country:
Country1
Country2
Country2
Values for Class Product:
Product1 (available ONLY for Country1)
Product2 (available for Country1 AND Country2)
Product3 (available ONLY for Country2)
Product4 (available ONLY for Country3)
I've read about derived properties and constraints as it might be my case.
Also some links might be related to the same issue:
https://softwareengineering.stackexchange.com/questions/386816/how-to-model-attribute-dependency-inside-one-class-in-uml-class-diagram
But for now I do not have a working solution.
For general purpose I've tried to represent these relationships with abstract Class diagram but it's hard for me to do this with exact values of these Classes within Object diagram

You would likely model that as association class:
The CountryProduct needs to filled with the according information (so it my contain the price which is used for a product in a country).
You "could" model that as constraints on the association between Product and Country as well. But I'd bet that business will not be happy with that since it sets all in concrete when coding, while business expects quite some flexibility here.

Just use an Association between Product and Country. If you want to capture attributes for each Product-Country-pair, such as the price mentioned by #Thomas, an AssociationClass is the natural choice.
In an Object-Diagram Instances of the Association (links) can be shown as lines. You would have lines between Country1 and Product1, and Country2 and Product2 and Product3...
This could be used to illustrate the structure of your system and how it evolves over time. To really define it, other diagrams are better suited.
I don't see, how constraints on the Association can help. Textual Constraints could be on some additional Class Selection. The start of the constraint could be: context Selection: product = product1 implies country in (country1). This would not allow to later add new products. And the constraints defined by the Links between countries and products are much more readable.

Related

How to represent merchandise flavours (or product variants)?

I have the following UML diagram:
Where VarietyCategory could take values like size and colour, and Variety for size could be S, M, L, and for colour could be green, red.
Now I can have a stock per combination of varieties, taken from the Cartesian product of all the variety categories a merchandise have (for example, 5 S-green items and 10 M-red items). How can I add this information to the UML diagram?
I guess I'm seeing this as an optional association class from Merchandise to the space defined by the Cartesian product of all the VarietyCategorys with a quantity attribute specifying the stock for that given combination, but I can't see how to express that in UML.
After thinking a bit I've come up with this, but this doesn't seem to fully convey the intention, as I had to put a note to specify a multiplicity depending on another part of the diagram, along with the constraint of selecting a variety from each variety category:
Any better ideas on how to do this?
The problem
This is indeed a popular scenario in some industries such as apparels, where each item in the catalogue is configurable regarding size, color and style.
The stock of a configurable merchandise such as "Shirt" does not make sense except for statistical purpose, but what really matters is the stock of the configured merchandises, e.g. {Item: "Shirt", size: "M", color="white", style:"italian colar"}. Here it's even more complicated, since the configuration elements are dynamic.
Your solution
Your second diagram models this very well by using a combination that you've called Flavor. So for the shirt, each possible combination of the configuration variables (Variety), e.g. the tuple ( "M","white","italian colar) would be a distinct flavor. Your association would class would hold the stock quantity of the Flavor.
The multiplicity on the Variety side would be by deduction 1..*. The constraint then needs to express that for an occurence of Flavor, the size of set of associated Variety occurrences is the same than those indirectly associated with the Merchandise. A full-text expression like you did is just fine. The other alternative would be to express this with a complex OCL predicate, which is very difficult considering some missing role names and the multiple indirections. Btw, most readers wouldn't anyway understand it.
However, I would not keep this solution:
Its main weakness is that the Flavor seems independent from the Merchandise, whereas in reality it only makes sense for a given Merchandise (your constraint proves it).
It is not easy to manage more complex stock, for example if you'd have a stock per warehouse.
Better alternatives
If you'd consider Flavor as a flavor of a given Merchandise, you could make this explicit and simplify the design: Flavor would become the configured Merchandise (instead of just a combination of Variety) and could make it a component of the Merchandise composite.
You could then simplify and store the stock quantity at the level of the Flavor . Or you could manage the stock quantity in an association class between the Flavor and a Warehouse (which you could not really do with your current model).
Everywhere you'd use a Merchandise, you'd use a Flavor instead, facilitating for example the ordering or the shiping of configured products, which is much more difficult if you'd keep the flavor independent of the merchandise.
To avoid confusion, it would nevertheless be better to rename Flavor in something more explicit that reminds that it's a product that you manage in your system.
A product variant (like Tesla's Model 3 in Pearl White with Sport Wheels) for a product (like Tesla's Model 3) has all features of the product (like a top speed of 140 mph) and additionally a set of attribute-value slots for all variation attributes of the product (like "Paint" and "Wheel" in the case of Tesla's Model 3). This is described by the following class diagram:
The diagram includes data samples next to classes for illustrating their meaning.
Notice that using composition for associating variation attributes to products and variation attribute values to variation attributes means that these attributes and their values are specific and not shared among products/attributes.
A corresponding relational database schema can be read off from this model:
products( id, vendor_id)
product_variation_attributes( id, product_id, name)
variation_attribute_values( id, product_variation_attribute_id, value)
product_variants( id, product_id, price)
variant_slots( product_variant_id, product_variation_attribute_id, variation_attribute_value_id)
This model/schema is compatible (modulo renaming) with the confirmed answers
https://stackoverflow.com/a/19200349/2795909 and https://stackoverflow.com/a/24941744/2795909.

How to express counter type entity with UML?

I would need some help with a problem we're facing in a company, trying to model every process and entity.
So far we have used an enhanced conceptual model with entities and attributes with relationships but there are some objects that don't exactly match a dimension or a fact table, and this is an entity that can be called "Shops with sales over X units". There is the entity "sales" and "shop" obviously, that would have it's representation in UML as independent entities and represent at the lower level, each sale and shop.
What we need to indicate in UML is an entity that stores the counter of shops with sales over X units, so this has some kind of behavior or conditions.
If we consider the entity, it would need date-from and date-to, and the value (counter), and creating a connection with the shop entity seems enough, but we miss the behavior that expresses "more than x sales". So the behavior could be for example: Go to the shop entity, take the 1st element and navigate to the sales entity, calculating the sales. If it's over X, then value+1, and so on.
I made a simple version of the problem. Blue boxes represent the entities already created, and the orange one is the counter that should count the shops with some constraints.
Is there any way of using some kind of UML diagram that can help us to solve this problem?
You could realize that with an association class:
ShopSales relates Shop and Sales so you can store the number of sales along with other things you might need in that conjunction. The ShopSalesStats could give you the shops by number of sales.
Another (of many) way(s) would be to just hold the count as public property of Shop and let ShopSalesStates handle the counts on all associated Shops.

UML Diagram for program

I have to complete a program that implements a car Park system.
I started with the UML diagram as I think it is easier for the program to be done after that, but I am a bit stack.
The scenario is:
Design and implement a class Vehicle (abstract) and the subclasses Car, Van, Motorbike. The classes should include appropriate methods and hold information about the ID plate of the vehicle, the brand of the vehicle and the entry time/date in the parking.
In particular:
• The Car class should also include appropriate methods and hold information
about the number of the doors of the car and the color.
• The Van class should also include methods and information about the cargo
volume of the van.
The class Motorbike should also have methods and information about the size
engine of the motorbike.
You should implement a class DateTime to represent the time/date of the entrance of
the vehicle in the parking. Do not use any predefined library.
Design and implement a class called MyCarParkManager, which extends the
interface CarParkManager. MyCarParkManager maintains the list of the
vehicles currently in the parking.
The class should display in the console a menu from which the user can select among
the following management actions:
• Add a new vehicle in the parking if there are free lots (considering that the max number of lots is 20) and return the number of the free lots remaining. Consider that a Van occupied 2 lots. Display a message with the number of free lots or informing that there are no lots available.
• Delete a vehicle, selecting the ID plate, from the list when the vehicle leaves the car park and return the vehicle instance. Display the type of the vehicle leaving the parking (if it is a car, a van or a motorbike).
• Print the list of the vehicles currently parked. For each vehicle print the ID plate, and the entry time and the type of vehicle (if is a car, a van or a motorbike). The list should be ordered chronologically, displaying the last vehicle entered in the parking as the first in the list.
And this is what I've got so far. My Solution
Since class Vehicle is abstract and cannot be instanced, what should I use to create different vehicle objects, might it be an array? And how should the output be changed, I mean depending on what the input is going to be: If it is car, to ask for color also, if it is a van for cargo volume?
Thanks a lot in advance to who take the time to read it and see if this UML seems right.
Analyze the statement
An important skill that you will start to develop in this module is analyzing a problem statement in order to identify the details needed to develop a solution.In this assignment the first task you should perform is a careful analysis of the problem statement in order to make sure you have all the information to elaborate a solution. Do not make assumption about what is needed! If you are not sure, about the information provided, ask questions.
Design a solution:
The design of your system should be consistent with the Object Oriented principles and easy to understand by an independent programmer.
Source: 5COSC001W Object Oriented Programming - Assignment 1
Suggest you:
class: "VehicleCardInfo" for storing cars information and status
class: RulesForCarPark for validate all data in "VehicleCardInfo"
vocabulary for: car types e.t.c.
CarParkManager as Actor use UseCase "Managing Cars" for CRUD operation for "VehicleCardInfo" objects.
Maybe we need some rules for people to logging and use this application.
UML diagram maybe easy for above (we don't use associations, use dependency).

Conceptualization: generalization or not?

I'm modeling an app which will let users look for real estate properties. So it's going to be a website where users will be able to look for rentals and sales on houses, flats, castles, grounds, shops, parkings, offices. According to that, I'm hesitating in the class diagram. Should I generalize all the type of real estate properties, written above, from the class RealEstateProperty or should I just associate to it a class TypeOfRealEstate, knowing that the type "Ground" for example can be as well a real estate property as the ground of a property like a House or a Castle. Also a parking can be a real estate property as well as a parking of a House.
Anyone has an idea of what's the best way to do that ? Thanks in advance.
It depends of what features of different RealEstates your system has to implement. A class's features include attributes, methods and associations.
If all your potential RealEstates have same features, for example ID, type, price, date and responible agent, and you don't need to firther differenciate among them, than the associated type will do the work. Model RealEstateType as an Enum (or even class, if you expect to add new types) and associate it to a single RealEstate class.
If different RealEstates, on the another extreme, need to have different features, you will need to inherit those from the base abstract class. For example, Ground have an attribute "area", while building has "number of floors". Even methods can be different, or associations.
Following your example, you would like to link Ground to House. This is much cleaner in the second version - just an association between Ground and House class. In one-class version, you would have to link the RealEstate with itself and add spacial restrictopns (very "ugly" design).
In summary, try to think about the features of different RealEstates and make your RealEstate hierarchy based on their differences.
You can end up with a single class or several dozens of them. :) Try to keep this hierarchy as simple as possible (less classes), but enough to mark their different features clarly.

UML Class Diagram - Notation for 'OR'

I have 4 tables:
Doctors
ID,Name,roomNumber
Appointments
ID,whenOccured,ifAttended
Patients
ID, name, address
DPappointments
DoctorID,PatientID,AppointmentID
this roughly becomes
However, i now want to change it such that an appointment can be made to see either a Doctor OR a NURSE?
How can i change the class diagram to reflect an 'OR' type relation?
Depending on the rest of your model's structure, there are different solutions. I supose there is also a class Nurse and that id does not have any special relationship with the Doctor (like inheritance from Employee or similar). So, this would be a generic solution.
Add add an association between Appointment and Nurse, similar to the existing one with a Doctor. The corresponding multiplicity on the Doctor (and Nurse) side should be 0..1 and an additional rule should be added - an Appointment object must have either a link to the Doctor object or to a Nurse object.
This rule could be specified in OCL (if you like a formal style) or as a simple textual note on the diagram.
There are some other ways to model this, with no additional restrictions, but the model itself would (maybe) be necessery complicated. For example, you could derive Doctor and Nurse from an abstract class - AppointmentRespondent and link it with the Appointment using the multiplicity 1..1 on that side. This model permits more flexibility and is more exdensible (easy adding new potential AppointmentRespondents), no OCL, no restrictions.
It's up to you to chose the method that is more in line with your model and future extensions.
P.S. Not that this is not an OR-type of relation, but rather XOR - in each Appointment there MUST be somewhone on behalf of the hospital (this is a reasonable guess :)).

Resources