|
-
May 20th, 2009, 06:51 PM
#1
Oop
I'm having a hard time understanding OOP. If I have two objects, customer and employee I should create a person class which declares fields that are common to both like first, middle, last name then inside the employee class I can declare social security number, hire date, etc. But I also need to track the address of both. Home address for employee and billing and shipping address for customer.
I have seen one example that uses a class call Address that declares stuff like street, city, state, zip. The address class is simply referenced from both employee and customer classes. But I don't think this is so much OOP as it is trying to reduce code duplication by not declaring the address details over and over again within every class. Maybe OOP is supposed to reduce code duplication. An employee is a person but its not an address.
Then I have things like phone number which was a seperate class the class has a couple fields, area code, digits and extension.
Both customer and employee reference the phone number class something like
Code:
PhoneNumber home
PhoneNumber cell
Address shipping
Address billing
But I also have things like email address and website. Email address is used in both employee and customer so should I be making a new class called Email having two fields like, user and domain defined?
I have some stuff that is database specific only like "deleted" that so that when querying the database I can filter out all employees or customers that have been soft deleted but still exist in the database. Each employee or customer has a inique ID assigned to it that is only used to help the database locate the correcrt record during inserts/updates etc. This ID is never shown to the user and really doesn't belong to the employee or customer its just an internal piece of data. So technically with OOP this information is not part of a class and shouldn't be included in the class. Yet it is needed by the program. So where does it fit in? Do I create another class called DataStoreFields to hold this data?
I need to learn stuff for class but it makes my head hurt sometimes. Because I'm not supposed to include fields in the class that do not belong to the class using OOP but sometimes I need fields/data that don't belong to a class. A person walking down the street has a name they might have a phone number and if they are not homeless they have an address, but they don't have a database ID.
I can't get it stright in my head.
Thanks,
- pgrammer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|