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?
Entities are usually objects defined by classes with variables that store values of simple objects that represent important application data structures. This package provides an implementation of simple classes that can be used define entity objects that can provide their own consistency checking methods.
An entity class is essentially an object wrapper for a database table. The attributes of an entity are transformed to columns on the database table.
Some reasons for using entities are: When the key is a property of an entity object representing the record as a whole, the object's identity and concept are often clearer than with key and value objects that are disjoint. A single entity object per record is often more convenient to use than two objects.
Example of entity classes are: computer, department and company. All computers in the company share attributes, all departments share attributes and all companies share attributes. An entity is an instance of an entity class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With