uba2012
uba2012

Reputation: 385

Sales system datamodel (Logical)

I have tried to make a logical data model, but I am not totally sure if it is modeled right. It is a very cut-down and basic model, but overall I want to know if it is modeled the way is should be.

Data Model - Sales system

Furthermore, how do I convert this into a class model in object oriented programming? I guess I need:

Class Customer: int id, string name 
Class Order: int id, string date, Customer object 
Class Item: int id, string itemName, string item Desc 
Class OrderItem: ?

Upvotes: 1

Views: 417

Answers (1)

Jason White
Jason White

Reputation: 5813

For your data model, you don't need the relationship line between Orders and Items. You're using the junction table Order_Items to represent that many to many relationship.

As for the class models, you won't need a class to model the junction table. You can simply model it with a collection of Item in your Order class. The relationship between the Order and Item class is a composition relationship. You can think of it as: An Order has-a Item or an Order has-s collection of Item.

Here is how you can model the Order class in java.

public class Order {
    private int id;
    private Date date;
    private Customer customer;
    private List<Item> items;  // you could use other collection types as well.

    ...
}

Edit:

Also for your many side of the relationships, you may consider using "one through many" line (crows foot with a line)" as opposed to "zero through many" (crows foot with circle). A order generally has atleast 1 item and atleast 1 customer. An order isn't an order without a customer or items.

Upvotes: 1

Related Questions