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 MobilePhoneNumb er. The only
difference with the normal PhoneNumberClas s is that it is of the type
MobilePhoneNumb er (usage: A function only accepting MobilePhoneNumb er
Objects for sending text messages). I would like to create a MySQL
table that consists of mobilephonenume rid'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 MobilePhoneNumb ers class which create a
phoneNumberObje ct if it does not exist?
Hope that my problem and questions are clear, if not please ask for
more info.
Thanks in advance
Marijn
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 MobilePhoneNumb er. The only
difference with the normal PhoneNumberClas s is that it is of the type
MobilePhoneNumb er (usage: A function only accepting MobilePhoneNumb er
Objects for sending text messages). I would like to create a MySQL
table that consists of mobilephonenume rid'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 MobilePhoneNumb ers class which create a
phoneNumberObje ct if it does not exist?
Hope that my problem and questions are clear, if not please ask for
more info.
Thanks in advance
Marijn
Comment