Hello.
Suppose you had a class called “FunVacation” and that the class contained a collection of “Steps”, this steps are what make your vacation a fun vacation. Now suppose each step can be any of the following options:
Payment
SortOrder
PaymentType
Amount
Activity
SortOrder
Description
ScheduleTime
Feeding
SortOrder
FoodType
TotalCalories
As you can see, all “Steps” have one property in common and the rest of the properties are unique to each step. The common property called “SortOrder” is used to determine the order of each step (when it should take place). So a typical “FunVacation” would look something like:
FunVacation
Payment (Visa, $500)
Activity (Play Golf, 1 hour)
Activity (Swim at the pool, 30 minutes)
Feeding (Eat hamburger, 500 calories)
Activity (Go fishing, 4 hours)
Activity (Get a massage, 1 hour)
etc.
So here are my questions, assuming that the FunVacations you schedule always have the same type of steps, either a Payment, an Activity or a Feeding step:
How would you design this?
1. Would you create one distinct class to represent each type of Step and have Steps inherit from some base class or some interface that implements the SortOrder common property?
2. Would you create one class to represent all Steps and add some kind of dynamic properties mechanism to be able to add or remove any number of custom properties on the fly for that single step?
And how would you store the information in the database?
1. Would you create one data table with a bunch of columns so that all Steps can be stored in the same table? Basically, you would end up with a bunch of null columns that are not used because the particular Step you are storing only uses certain columns?
2. Would you create a single table with some kind of key/value storage mechanism? Basically, one column would represent the property name and the other the property value.
3. Would you create one table to store Payment steps, one table to store Activity steps and one for Feeding step?
Thanks for your feedback.
Copyright (c) Marimer LLC