A fruity Blog
Friday, October 20, 2006
Design patterns - Decorators
Ahhhhh. Just back from Italliana and fully charged full of new freshly squeezed programming zest. While on my little trip around Napoli I was graced with much amazing pizza and pasta which helped me relax my mind into the higher zen ways of design patterns. A work mate lent me a book of high level design pattern abstractions and interpretations to mull over while journeying and a lot of things have finally started falling into place in the original design of the php classes. Although I'm only half way through the book the Strategy,observer,decorator and factory pattern have all been covered, all of which I have encountered in the past. In my code I've been using decorators to levy the functionality of existing components with added tids bits without tying them into tight coupling.
The thing I didn't realise was that this concept can be taken further to build up functionality in layers of inheritance, invisible to the high level code. For instance if I have a calendar month that needs to be displayed in a variety of different ways there should always be one base class that extends the original month decorator. So say a month is a text month of events as opposed to an HTML or XML month of events that had to be built to enable the functionality of text readers. The text month of events would not need the extra tags HTML and XML will need surrounding the text. The HTML will have all the ability of the text version's display but also will add in surrounding tags to the source. Before I knew this I was making a manager that would deal with different 'instances' of certain kinds of decorated calendar month. A bit backwards, but I know better now.
Also just had a small revelation that I was coupling my event too tightly to a calendar day.
The thing I didn't realise was that this concept can be taken further to build up functionality in layers of inheritance, invisible to the high level code. For instance if I have a calendar month that needs to be displayed in a variety of different ways there should always be one base class that extends the original month decorator. So say a month is a text month of events as opposed to an HTML or XML month of events that had to be built to enable the functionality of text readers. The text month of events would not need the extra tags HTML and XML will need surrounding the text. The HTML will have all the ability of the text version's display but also will add in surrounding tags to the source. Before I knew this I was making a manager that would deal with different 'instances' of certain kinds of decorated calendar month. A bit backwards, but I know better now.
Also just had a small revelation that I was coupling my event too tightly to a calendar day.
Monday, October 02, 2006
Current status
I've only recently saw any value in updating my log since I've just started making any progress. Going back to the start over my original code is both fun and torturous. I'm making some good progress and I'm pretty confident I'll have a working distributable version of fruity out for christmas. So far I've got a few new classes and a few redundant ones. I'm leaving all of the artist and venue management stuff just now and will include it as a plugin probably in the next version.
I've written a whole bunch of installation test classes that I will continue to maintain as I think i will be a great way to show if you have actually got everything installed correctly. It may be pretty obvious to some but I think if peeps start editing the files and stuff it will be one less load of things that could slip through the debugging net.
As for the actual code I've written these test classes:
TestConfig.php
TestDateMgr.php
TestEvent.php
TestEventMgr.php
I've only just found out how to make proper mock objects in simpletest so I'll take another day or two with the existing tests to make them into the correct mocks instead of just using canned data form a hardcoded Mock class. I'm really busy just now on other projects and commitments so I'll probably stumble at this point until next month. After I have the eventMgr classe working I'll ge tteh display and auth working and I'll be right back to having a viewable page :)
I've written a whole bunch of installation test classes that I will continue to maintain as I think i will be a great way to show if you have actually got everything installed correctly. It may be pretty obvious to some but I think if peeps start editing the files and stuff it will be one less load of things that could slip through the debugging net.
As for the actual code I've written these test classes:
TestConfig.php
TestDateMgr.php
TestEvent.php
TestEventMgr.php
I've only just found out how to make proper mock objects in simpletest so I'll take another day or two with the existing tests to make them into the correct mocks instead of just using canned data form a hardcoded Mock class. I'm really busy just now on other projects and commitments so I'll probably stumble at this point until next month. After I have the eventMgr classe working I'll ge tteh display and auth working and I'll be right back to having a viewable page :)
Events and the 'decorator' pattern
The post pror to this one was done when I was round at a mates and very much confused and isolated from the internet so I posted it later. Heres the deal. The 'Events' have all unwittingly tried to implement the decorator pattern when I was just plugging away but I didn't know what they were so didn't understand how it was architected. Basically for all those not in the design pattern 'know', a decorator is the term given to a pattern that instantiates a class below it but adds a new level of functionality to it. This is to save continuous subclassing. So for example, if you have a picture you could use the BorderDecorator to put a border round it and a FrameDecorator to mount it on a frame. Its basically just layering in small steps without changing the initial class.
Sunday, October 01, 2006
What the Hell is all this?
I'm looking at this code and I'm wondering what the hell some of it does. Why the heck have I got these Calendar Decorators as parameters to the events? When I originally wrote the code I was none the wiser about design patterns so I just tied it in anyway I could to make it work. I've ended up with this which is now something of a muddled hodge podge. Dearie me.
Thursday, September 28, 2006
Woooooo TestsARific
I'm certainly cooking with gass now. It has taken a Long time but I have finally got right into the swing of things. i can now say that i can confidently pump out labout three methods a night with tests and all. I've Made an Test install class that will test all the configured classes against those that are installed and give out if they are all ok. Then I've Made a fully equipped date manager. I feel a bit like I'm reinventing the wheel anytime I go near dates but I think its important to revisit all my old code and refactor it as much as I can. Now I've got all of my old dateMgr class tested I've got to get this back into subversion.
A late post
Ah dear I seem to have lost the rhythm, its been a few weeks since I last posted but its certainly no because I didn't want to work on fruity its just because life gets in the way.
Annoyingly I've been trying to make a class that keeps a persistent DB connection but its just not been for happening. I think its probably mostly down to my understanding of the syntax because the majority of my time has been spent weeding out errors. I've written an extended html reporter for simpletest and have started on the installation tests so I feel a bit better. The reason it took so long was just because I didn't understand that you had to connect to the database before every query. There must be much more efficient ways of doing this but I'll leave that to the future and just start making some progress. Wow this really was a padding post. But here I go, here I go, here I, here I go, Yo!
---I made this ages ago but it just sat on my desktop and didn't get posted to the blog.
Annoyingly I've been trying to make a class that keeps a persistent DB connection but its just not been for happening. I think its probably mostly down to my understanding of the syntax because the majority of my time has been spent weeding out errors. I've written an extended html reporter for simpletest and have started on the installation tests so I feel a bit better. The reason it took so long was just because I didn't understand that you had to connect to the database before every query. There must be much more efficient ways of doing this but I'll leave that to the future and just start making some progress. Wow this really was a padding post. But here I go, here I go, here I, here I go, Yo!
---I made this ages ago but it just sat on my desktop and didn't get posted to the blog.
Thursday, August 24, 2006
De do up de
I know man, I know. Pretty shoddy Kev pretty shoddy. But I'm getting round to giving it a make over and its getting late. I tried to do it on my macbook and just completely failed. But Css is familiar ground so I thought I'd just spend an hour or so giving the place a lick of paint.
Monday, August 21, 2006
An Agile approach
Dash. I had a whole train journey but no laptop because I forgot my frigg'n AC adaptor. But it got me to thinking how I'm actually going to go about adapting fruity into a real project. I'm going to have to decise proper tests for everything and for what its worth I don't think The exisiting code is so amazing that I couldn't just rewrite the thing with the grace of hindsight and experience. I'll be able to save alot of the logic in the code which is the main thing. I'm going to try and adopt an agile approach as best I can and build based off of the user stories. So I'm right back to "User can view a Calendar". Yeah so I'm goign to do that...if none of this reads well ah well. I'm watching the Texas Texas Massacre documentary off of the special edition. Yeah pretty damn good.
Dev Setup - Mac finally up
(Actually Friday 18th)
Woooooooo. It's up and running! All it was that my include paths were not set up correctly so I should have known that. At the mo I'm just tearing ahead and working with a different development environment setup so I can start testing. I'll have to change all of the config files back so they don't soley rely on the php.ini's include settiings as this isn't the most user friendly of solutions. The best idea is to have a load of constants in the class_Config.
Woooooooo. It's up and running! All it was that my include paths were not set up correctly so I should have known that. At the mo I'm just tearing ahead and working with a different development environment setup so I can start testing. I'll have to change all of the config files back so they don't soley rely on the php.ini's include settiings as this isn't the most user friendly of solutions. The best idea is to have a load of constants in the class_Config.
Friday, August 18, 2006
Dev Setup: Mac /Mamp/ Pear Installation dir where are you?
Okay I type:
$pear list
and I can see that DB and others are installed but God knows where they actually are installed to. I'm searching for DB.php but to no avail. Its a bit troublesome when trying to include them.
*Edit* 10:57pm
Right So I tried to track down the PEAR packages and failed. So I thought I'd just copy over the whoe folder into my eclipse workspace and reference the files directly. For some reason even when I'm doing this it wouldn't go further than one folder deep into the hierarchy so I dumped that aswell. I'me trying to get my index page working by gradually adding the includes that it uses but when I add the one for PEAR/Calendar/Month/Months.php it just gives me an empty screen... I've just had a thought. Maybe the pear that my machine is using is not the mamp one. That would explain the lack of packages in the directory.
*Edit* 23:09pm
Oh you Beauty that was it! On the down side that means I'm running a useless server everytime I boot From when I messed up my original attempts to install apache and stuff.
*Edit* 00:55pm
Hmm Well PEAR is definely installed but I don't know why my classes aren't generating the table. Its not like there is any output errors to go on either. It doesn't seem to like my Auth class very much. When I go Sess->start() it freezes up. What could that be then?
Righty I'm going to do this on the train down to my girlies tomorrow and I'll see if I can make any progress then. Nighty. x
$pear list
and I can see that DB and others are installed but God knows where they actually are installed to. I'm searching for DB.php but to no avail. Its a bit troublesome when trying to include them.
*Edit* 10:57pm
Right So I tried to track down the PEAR packages and failed. So I thought I'd just copy over the whoe folder into my eclipse workspace and reference the files directly. For some reason even when I'm doing this it wouldn't go further than one folder deep into the hierarchy so I dumped that aswell. I'me trying to get my index page working by gradually adding the includes that it uses but when I add the one for PEAR/Calendar/Month/Months.php it just gives me an empty screen... I've just had a thought. Maybe the pear that my machine is using is not the mamp one. That would explain the lack of packages in the directory.
*Edit* 23:09pm
Oh you Beauty that was it! On the down side that means I'm running a useless server everytime I boot From when I messed up my original attempts to install apache and stuff.
*Edit* 00:55pm
Hmm Well PEAR is definely installed but I don't know why my classes aren't generating the table. Its not like there is any output errors to go on either. It doesn't seem to like my Auth class very much. When I go Sess->start() it freezes up. What could that be then?
Righty I'm going to do this on the train down to my girlies tomorrow and I'll see if I can make any progress then. Nighty. x