Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.