Don't ask to ask, just ask | |
PerlMonks |
So, what's an object attribute anyway?by Nomad (Pilgrim) |
on Jul 22, 2010 at 13:02 UTC ( [id://850841]=perlmeditation: print w/replies, xml ) | Need Help?? |
When is a thing part of an object's state and therefore an attribute, and when is it something else? Take an object, let's call it a node. Say you occasionally modify these nodes and you want to record the time you've modified them. Is that modification time part of the state of the object or is it a property of the surrounding framework in which the modification was carried out? And what does 'modified' mean anyway? Is deleting the node a modification? What about changing who has read access to it? Or is that a modification of the authorisation sub-system? The mind boggles. Why I've come to meditate on such mind-crushingly philosophical questions is because of the development I've been doing on Everydevel, or should I call it 'Omnia' the web CMS that is/was the basis of perlmonks and several other web sites. Say that you use this CMS to publish articles on the web. These articles are true gems of insight that add to the sum of human knowledge and benefit the entirety of humanity. Sometimes, however, the articles have errors. You wish to correct these errors and in the interests of full disclosure, you want to publish the times they were modified. Is that modification time a property of the text of the article, of the html which marks up the article, of the unique URL that points to the article, or something else? Your articles are represented in perl as objects, i.e. blessed hashes. These inherit from a class of objects called a 'node'. You want to store all these objects persistently, and you choose a relational database to do so. You create a table called 'node', do you have a field called 'modified' to store the time that the 'node' was 'changed'? What if you have thousands of rows in the table and the most common value for the modified field is 'NULL'. Aren't you now breaching First Normal Form? Should you rethink your design? Instead of having a row called modified, what about another table called, say, 'object_state_changes', that records when the node objects were modified? Or, what about a table called, say, 'significant_dates'? This table would not only list 'modified' dates but also, date of object creation, publication, withdrawal from publication, second publication and so on. And what does all this mean for the application logic? Irrespective of how you decide to store the the date of modification, should 'node' objects have a 'modified' attribute? Or should that piece of data be accessed as a method of the database interface? And while we're at it, what is an object attribute anyway? All this, and all I wanted to do was serve some html. UPDATE: Thanks all for your replies. Now, I see that for this project the 'modified' attribute is in fact a flag to indicate whether an object is in its initial state and when it was taken out of that initial state. This is different from a date an article was 'published' or 'updated'. I'm going to be tweaking the db design and object model to reflect this.
Back to
Meditations
|
|