|
Posted by Marijn on 06/03/07 19:33
Hello everybody,
I am new to PHP and working on extending my knowledge of OOP. The
posts in this group concerned with whether or not to use an OO
approach when programming in PHP is not what I want to discuss in this
post. Rather I would like to discuss the best way to program the
following problem:
I have a MySQL Database which for example exists of phonenumbers. The
table might look something like this.
+---+---------------+------+
|ID | PHONENUMBER | FLAGS|
+---+---------------+------+
|001| 612341234| FALSE|
+---+---------------+------+
|002| 612341235| TRUE |
+---+---------------+------+
|...| ...| FALSE|
+---+---------------+------+
|00N| 612341238| FALSE|
+---+---------------+------+
An object representation in PHP might be the object PhoneNumber. The
object PhoneNumber would be extended from a general class called
Entity. The class Entity allows for easy creation of new database
objects. Say I would like an EmailAddress object, I would simply
create the MySQL table, extend the Entity class with an EmailAddress
class and populate the SQL variables with the correct SQL statements.
Until this far everything is ok. But what if I would like an extended
version of the objects PhoneNumber or Emailaddress? Say for example
that I would like an object called MobilePhoneNumber. The only
difference with the normal PhoneNumberClass is that it is of the type
MobilePhoneNumber (usage: A function only accepting MobilePhoneNumber
Objects for sending text messages). I would like to create a MySQL
table that consists of mobilephonenumerid's and phonenumberid's.
What would be the best way, rewriting the internals of the Entity
class and just fetch the data from MySQL right away or writing new
internals for the MobilePhoneNumbers class which create a
phoneNumberObject if it does not exist?
Hope that my problem and questions are clear, if not please ask for
more info.
Thanks in advance
Marijn
Navigation:
[Reply to this message]
|