lundi 30 novembre 2020

How design models and database with animals example use case?

I have a project that is becoming more complex by the time and I am feeling that I have to reorganize the way the Models was designed, but I am stuck in decision which direction to go.

To make the long story short...

Let's suppose that I have Animals: Parrot and Toucan (They are Birds) and Iguanas (Is a Reptilian). Deep inside theses three types of class are all Animals...

They have/do some aspects in common like eat(); sleep(); poop(); and have nickname and status, but Reptilians and Birds is for different purpose and do different things too...

In my application I will never deal with Animals directly, only Iguanas, Toucan or Parrot.

I kindly ask for some suggests of what Design Pattern should I use in this case. I have doubts on how to organize it into the database too (which class will be tables)...

Here what I am thinking about:

I am planing to implement Composite Design Pattern... am I right?

Declaring Animal as Abstract Class holding the common fields (nickname,status) and declaring the required methods (eat(); sleep(); poop();) as abstract too... so Parrot, Toucan and Iguanas can implement your own way to do this stuffs. Is it right?

Things become more unclear when deal with database, in my vision will be three tables, one for each type of Animal (Parrot, Toucan and Iguanas) with your own fields (Toucan may have one or two fields that Parrot haven't). Is this ok?

Aucun commentaire:

Enregistrer un commentaire