Sunday, July 6, 2008

Style Size continue

Solution:
I took a whole month and more to get me back to blogging again. Well the solution was hard to get at. I mean initial design was to go with a tree diagram and the best solution for that seemed to be a XML structure. The best example for a hirearchial structure starting with a dummy root element and then having child elements to it, such that we have a structure from the first child to the children the combinations possible.

The list of items would be giving the combinations possible. Creating the XML would be the first step, next step would be painting the UI using the XML which would be pretty straightforward. Since we have the xml any selection made can tell at what level it fails. But this would be restrictive to the user since he would have to mke sequential selection instead of starting at any point he might wish to. So this design was not declined and there i was starting all over again

Here i got help from my manager. the new design was to create java objects which would be used to paint the screen. The object design was that instead of like in the XML model where we had only one way of navigation, here we would have objects for each attribute. But all the possible combinations would be made into one object called as StyleCombination. That is say if the item1 has attibutes of Regular super size, Red Color and Small size, the style combination would contain Regular, Red,Small as the object.

This way we would have to deal with objects and this would not be hirearchial too. So the next challenge was to tell me what are the style combinations that a particular object belonged to. So the ideas was to create a collection object for each attribute. This collection would contain the style combination as the objects. But one problem was to maintain just as many combination objects as there are items. And have the attributes belonging to the combination should refer to the same combination object instead of creating one more. That is the combination object Regular,RedSmall would be created only once and the collection for Regular , red and small would all contain this same object which is quite obvious. This way the memory would not be used much and we know if we have to update or change the property of item1 all we would have to do would be to change the property of the object and it would be reflected for other attributes too.

The way to create only one combination object can be done by overwriting the equals method to tell during comparision that these two objects are the same.

Rest of the painting adn selection was sounding to be very easy since we now have the model ready and the object hirearchy ready. But it did not turn out that esay since we had to include availabilty into picture and use paint listeners too. Rest would come in another blog. thats for today.

No comments: