0

I have two classes and I need to use best OOP design solution.

class Dogs extends Animals {
   CONST TABLE = 'dogs';
}

class Animals {
   public static function getAll() {
      // database query with table Dogs::TABLE...
   }
}
  • function getAll must be static
  • I know that function getAll can be abstract, but then I must rewrite it in all classes extends Animals so I need to avoid this behavior
  • I don't know if using table name as CONSTANT is OK (maybe better protected class variable?), but now I can call everywhere in project this constant
9
  • Why does function getAll() need to be abstract? Who's enforcing these restrictions? Commented Aug 21, 2014 at 7:30
  • @MarkBaker probably a teacher ;) Commented Aug 21, 2014 at 7:32
  • function getAll CAN be abstract, no restriction Commented Aug 21, 2014 at 7:32
  • @W.B. no school project, I am trying to do best OOP design for my personal project Commented Aug 21, 2014 at 7:34
  • 1
    @W.B.Yii is one of the worst PHP frameworks ever in the history. ActiveRecord is anti-pattern since it encapsulates table access and adds domain logic on that. He should be better using Zend Framework 2 or Laravel at least Commented Aug 21, 2014 at 8:13

1 Answer 1

1

If you deal with database or another storage, better to abstract it, use Domain Model pattern and Repositroy Pattern. Repository incapsulate all interactions with storage for example MySql and Domain Model incapculate business logic.

Sign up to request clarification or add additional context in comments.

2 Comments

Repository Pattern is about meditating over existing data mappers and domain objects. What you call here Repository Pattern is actually called Data Mapper/Gateway
Yes, Fauler call it mapper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.