I have two tables in the DB
- FuelStation (fuel_station_id: int (PK), fuel_station_name: varchar, fuel_brand_id: int(FK))
- FuelBrand (fuel_brand_id: int (PK), fuel_brand_name: varchar)
As we can see, both tables are linked via. foreign key (fuel_brand_id)
Now, I want to design an object model corresponding to the above data model but I am confused which approach to use from the following two approaches:
- Whether to make only one class
FuelStationand store fuel brand asStringin theFuelStationclass.
OR
- Make two classes:
FuelStationandFuelBrand. And then associate them with a Many-to-One relationship as one fuel station will have only one fuel brand but one fuel brand can have many fuel stations.
Q1. Which approach is better?
Q2. What are the pros and cons of each approach?
Upto My Knowledge:
Pros of Approach 2
It has made our object model more granular.
Acc. to good design principles, our object-model must be atleast as granular as relational-model. And approach2 follows that principle
Pros of Approach 1
- No need to create a separate object for FuelBrand for every FuelStation