I've been reading in basic concepts of OOP,as i'm trying to make this shift from transactional scripts to more oop manner in php, and i often come across this definition :
An object stores its state in fields (variables) and exposes its behavior through methods (functions). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication
and a simple example like :
Objects like real life objects have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail).
from definition i see that methods should be either manipulating internal state (setters) or communicating with other objects;
but when i try to apply this to a Blog example. composed of mainly 2 domains User and posts.
what could be the
User object Behavior ?
I cannt find any !
- login, its an auth lib. thing so i should not include it in user.
- posting articles is a Post object thing; again user conduct it; but its more of a post object concern to create a post right ?
User may be the main Aggregate object in a blog; yet the user is more like the Creator of Other Objects but he does not have a Behavior i can think of; he is being used -and his state- by other objects in most cases that all !
in a nutshell : what are allowed type of methods inside an object ?