10

I'm currently learning MVC as it pertains to php and I came across something called an entity class, but cannot for the life of me find a clear explanation and/or an example of it.

I thought it was a class that held the data from a database that the model retrieved and is then passed to a view, but i have this nagging feeling that I'm way off.

Can someone please explain it via an example or point me in the right direction?

zero
  • 2,999
  • 9
  • 42
  • 67
  • 4
    why the close votes? it's a legitimate question. – zero Dec 04 '12 at 20:28
  • 1
    See the answers [here](http://stackoverflow.com/questions/2550197/whats-the-difference-between-entity-and-class), which explain what an entity and a class are. Given that, an entity class is just a class that represents a real-world entity. – cmbuckley Dec 04 '12 at 20:28
  • ah ok so in the case of mvc an entity class would be a more specific class that the model calls on. example: the model is told by the controller that it needs database data of a specific type of user (lets say it admins) the model then instantiates a class who's only job is to retrive all cells and rows for all admin users the model then does logic on the data returned by that class – zero Dec 04 '12 at 22:17
  • Yes, that's a good example. The entity is the admin, and the entity class is the class that represents admins. In the same way that the admin entity inherits a number of properties from the user entity, the Admin entity class could extend a User entity class. – cmbuckley Dec 04 '12 at 23:36

1 Answers1

11

To expand on the comments above:

Your application models a real-world scenario, which will include a number of entities. The example entity you give is an Administrator; this entity likely inherits properties from a more general User entity.

Entity classes, then, are simply classes that represent your real-world entities:

class User {}
class Administrator extends User {}

An entity class only differs from a normal class in its semantic significance; a Controller class would probably not be an entity class, as it's part of the application framework rather than representing a real-world concept.

How your entity classes interact will likely be closely related to how your actual entities interact, so the relationships between entity classes (inheritance/association) will mirror your Entity Relationship Diagram.

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
  • THANK YOU, that's all i was looking for was some good clarification and guidance on the subject. the link you gave above was helpful, but this answer sealed the deal. thanks man. – zero Dec 05 '12 at 11:01