I'm looking for help identifying this design pattern and learning the "typical" vocabulary it uses:
I'm working on a project in PHP, and I've created a thin ORM layer that saves generic objects to and from the database. There are two classes that do the work:
- "my_object" is basically a container for various kinds of data. After being created this object can save itself to the db.
- "my_object_manager" is used to manage a set of objects, for instance if you wanted to retrieve many of them and iterate through them.
As a simplified example, you could do something like:
$post = new my_object('post');
$post->title = 'foo';
$post->body = 'bar';
$post->author = 'baz';
...and you if you wanted to load a bunch of posts you could do something like:
$posts = new my_object_manager('post');
$somePosts = $posts->getBy('author','baz');
foreach( $somePosts as $aPost ) {
...loop stuff here...
}
So, my question is this: In the class definition for "my_object_manager" I need to store a property that identifies what kind of object is being managed. It looks something like this:
class my_object_manager {
protected $theKindOfObjectThatThisManages;
function __construct($whatToManage) {
$this->theKindOfObjectThisManages = $whatToManage;
}
}
Now, forgive me for not knowing this kind of basic stuff, but I'm self-taught and have a pretty limited programming vocabulary. I'm sure this kind of design pattern is common, but for the life of me I haven't been able to figure out what it's called.
I'm trying to write code that other programmers can read and understand, SO, my real question is if you were reading this code what would you expect "$theKindOfObjectThatThisManages" to be called? What is this program design pattern called, and what do you call this kind of an object if you want other programmers to know what it's doing?
Lastly, the question editor popped up and told me that this question looks subjective and is likely to be closed. I hope that this question is, in fact, ok for Stack Overflow - but if not, where could I ask this question and get an answer?
Thank you!