karoma
karoma

Reputation: 1558

Going from object List to database

I'm just getting started on databases and could use some help. I currently have a program that handles car parking permits. You can add cars to the system, and associate a car with a permit. Up until now it was creating objects and storing them in 2 Lists: Car and Permits.

For example, my Car class is simply this:

class Car{
    private string regNumber;
    private string make;
    private string colour;
    private string owner;

    //constructor, getters, setters, ...
}

The Permit class is similar. It just has a permitID and a car registration.

I'm now making the jump to a database instead of using Lists to store the data.

However, as far as I can tell, using a database makes both of my classes redundant. Each tuple in the Car table will contain exactly what my Car objects contained, and I can do a join query to get Car data from a given permitID.

Is there a need for my classes anymore?

Upvotes: 0

Views: 111

Answers (1)

brendon
brendon

Reputation: 353

You may want to consider a class that is a car Car { long unique_id; int permit_id; ... String color; }
where unique_id is the primary key from a cars table. since the way you are explaining it in the question. Then to parse the SQL results consider using a simplified DAO Pattern to read the database into the application and use it.

Given the example, I am not sure why you would need two tables, a Cars table with a permit id value should be sufficient unless there is a reusable pool of permits, in which case you could create a static table with all permits in it.

Upvotes: 0

Related Questions