Home > Blockchain >  How to structure a project into Object Oriented framework?
How to structure a project into Object Oriented framework?

Time:10-08

I have a project and would like ideas/tips on how I could tackle it. This is the project

Each component in a car has a number. Example: "Hitch" has num: "43". I want to search and return every car model in the database (CSV file) that has the number "43". In the future, I would also like to be able to see information about the car model. Example: "manufacturer", "HP", then info about the "manufacturer" etc etc.

I have never done anything like this before, but I have researched and found that maybe OOP is the way to go? In that case, how could one structure it? enter image description here

CodePudding user response:

Since your main question is how do you break your requirement into an Object Oriented framework, I would structure it as follows:

You have objects called Parts and an object called Car.
Parts will have attributes: PartName(string), PartId(integer), PartManufacturer(string).
Car will have objects CarName(string), CarId(int), CarManufacturer(string).

A third object PartsInCar will track the relation between Car and Parts.
This object will have attributes CarPartId (int), CarId(Car), PartId(part).

Alternatively PartsInCar can also be an attribute of Car as a "vector of class Parts".
Depending on how granular you want to maintain the data, there is a possibility to create another class Manufacturer having ManufacturerId(int), ManufacturerName(string).

Now the question is how do you load your csv database into this structure ?
This depends on how your input data looks like. if you are doing the whole thing in memory, then you could use vector or dictionary to store the whole "list" of parts, cars and parts_in_car.

For each class defined above you will of course need member functions that will allow us easy operation.
E.g.:

  1. Cars object can have a member function that will return all Parts objects associated with it.
  2. Parts object can have a member function that searches all Cars and shortlists those cars that are using this part.

CodePudding user response:

you could use a dictionary with the key being the car name, and the value being a list of information about each car. You can assign certain aspects of the car to each index of the list to keep track of the data. you could use oop for this but it's a bit uncessary if I understood your question correctly

  • Related