Where would a senior PHP developer locate the method getActiveEntries()?
Posted
by
darga33
on Programmers
See other posts from Programmers
or by darga33
Published on 2012-11-04T01:26:45Z
Indexed on
2012/11/04
5:21 UTC
Read the original article
Hit count: 173
php
|object-oriented-design
I have a class named GuestbookEntry
that maps to the properties that are in the database table named "guestbook". Very simple!
Originally, I had a static method named getActiveEntries()
that retrieved an array of all GuestbookEntry
objects. Each row in the guestbook table was an object that was added to that array. Then while learning how to properly design PHP classes, I learned some things:
- Static methods are not desirable.
- Separation of Concerns
- Single Responsibility Principle
If the GuestbookEntry
class should only be responsible for managing single guestbook entries then where should this getActiveEntries()
method most properly go?
Update:
I am looking for an answer that complies with the SOLID acronym principles and allows for test-ability. That's why I want to stay away from static calls/standard functions.
DAO, repository, ...? Please explain as though your explanation will be part of "Where to Locate FOR DUMMIES"... :-)
© Programmers or respective owner