«« Next » « Previous
«« Next » « Previous

Link Details

We can't do it for you. Login and vote now.
Link 76682 thumbnail
User 228173 avatar

By mathewbyrne
via matbyrne.com
Published: Apr 22 2008 / 14:29

Modeling real-world objects with computer Data Structures is one of the more fundamental principles of Computer Science. Data Models however are often tied heavily to their storage medium, whether that be an SQL database, files on a filesystem or a web-service. The idea of implementing a Model/Mapper system is to decouple the format in which we wish to manipulate data from the format that we store it.
  • 8
  • 2
  • 1466
  • 439

Comments

Add your comment
User 233461 avatar

antych replied ago:

1 votes Vote down Vote up Reply

wtf, use __get, __set and __isset

User 228173 avatar

mathewbyrne replied ago:

0 votes Vote down Vote up Reply

You could definitely use __get, __set and __isset, you could even incorporate them into the class I demonstrated. The point isn't to make a Model class that can't be done in other ways, or even to make the highest performing class. It's to provide a framework for extending Models to eventually do things other than get and set with a nice syntax that can do the following:

$model->setField('value')->setFoo(1.5)-> ...

User 233461 avatar

antych replied ago:

0 votes Vote down Vote up Reply

You used __call to implement getters and setters, when __get and __set already exist for this purpose, the only thing you gained is fluent interface at a price of verbosity and some messed up code. Don't reinvent square wheels.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (8)



Voters Against This Link (2)