Jump to content

OOP: Class building help


Darghon

Recommended Posts

Hi all,

 

I'm pretty experience with OOP in PHP, but I'm looking for a good way to solve the next problem:

I have a base entity. This entity is saved in a database somewhere and a php object can get filled with it's record data.

 

This entity can have different properties defined with flags.

For instance, entity is animal, and a specific animal has the flag "can_fly", so I want the entity to allow flight functions.

Other animals might have a flag "can_swim", which invokes swimming functions.

 

Some animals have multiple flags etc...

 

so how can I best set this up, so that I can use record data to construct my object, with all needed functionality?

Without having to create 100's of functions in the entity object and checking if the required flag is set or not.

 

so a "extend on demand", or something along those lines.

 

Any other solutions for this problem would be great as well.

or tips about a design pattern that might resolves this.

 

i'm reluctant to using stdclass in php, so if possible, I'd like a solution that doesn't build a generic class, or a reflection class.

 

thx in advance

Link to comment
https://forums.phpfreaks.com/topic/266849-oop-class-building-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.