Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:48:09+00:00 2026-06-13T01:48:09+00:00

I have a dilemma on how to implement states for objects. Let’s say we

  • 0

I have a dilemma on how to implement states for objects.
Let’s say we have this:

class User {

     private $_active;// 1 or 0
     private $_deleted;// 1 or 0
     ...

}

These properties – as I see it – imply a state on User object.
What I would like to do is to define some events like afterActivate() or afterDelete() so I can chain my routines. I.e. after activation update some counters, after deletion also update some counters…

So I’m considering two approaches at the moment – first one is to create classes Activable and Deletable ( don’t mind the naming ) and then make User inherit those classes through a hierarchy of inheritance.

class Activable {

    protected afterActivate(){};

}

class Deletable {

    protected afterDelete(){};
}

class Activable extends Deletable {}
class User extends Activable{}

There are two problems that I see with this approach – first one is that class Activable now has implied Deletable state which is wrong and second problem is – if I have more states – 5-6 states the inheritance hierarchy may become quite complex. ( because User will extend the model class which will extend something else etc…)

The second approach is to use traits in PHP and use them to achieve this.
So I would have something like

class User{
    use Activable, Deletable; 

}

What approach would be better – maybe some 3rd approach?
Am I going in the right direction here?

Thanx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:48:10+00:00Added an answer on June 13, 2026 at 1:48 am

    Usually you would use Marker Interfaces for this sort of thing.
    I suppose this is some kind of ORM we’re talking about? Than I also assume there is some kind of object handling the persistence of your entities. Let that object check that $entity instanceof Deletable and act upon that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently came to this dilemma: let's say I want to use two
When I implement OAuth in iPhone, I have a dilemma to choose Safari or
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I have a dilemma. Let's assume(for simplicity's sake) I have four tables, with different
I have this dilemma many times - and I would like one time and
I have a dilemma with this one. With the following code I am able
I have a dilemma with this, I am designing a project and basically it
When I have to implement equality comparers for public class SampleClass { public int
I have this dilemma. I'm developing a web services. It has to return a
I have this dilemma with JavaScript. I need to convert a list of dates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.