<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Object Oriented Era Begins</title>
	<atom:link href="http://ooerabegins.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ooerabegins.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 26 Jan 2011 08:07:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ooerabegins.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Object Oriented Era Begins</title>
		<link>http://ooerabegins.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ooerabegins.wordpress.com/osd.xml" title="Object Oriented Era Begins" />
	<atom:link rel='hub' href='http://ooerabegins.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Easy Data Access In Pages Of GWT/Swing Application</title>
		<link>http://ooerabegins.wordpress.com/2009/06/30/easy-data-access-in-pages-of-gwtswing-application/</link>
		<comments>http://ooerabegins.wordpress.com/2009/06/30/easy-data-access-in-pages-of-gwtswing-application/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 04:15:40 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Desktop Application]]></category>
		<category><![CDATA[GUI Pattern]]></category>
		<category><![CDATA[GWT Design Pattern]]></category>
		<category><![CDATA[GWT Pattern]]></category>
		<category><![CDATA[HMVC]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=58</guid>
		<description><![CDATA[When developing desktop based or similar applications, it becomes headache to synchronize data between different pages. Say when Delete is clicked in context menu of some node of tree, Grid and some other panels need to be notified. Here is one simple way for accessing data of other panels. We have singleton session object (only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=58&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When developing desktop based or similar applications, it becomes headache to synchronize data between different pages. Say when <em>Delete</em> is clicked in context menu of some node of tree, Grid and some other panels need to be notified. Here is one simple way for accessing data of other panels. We have singleton <strong>session</strong> object (only one object at runtime) at each client’s runtime. So when we have some data that need to be used in other pages, we can put those objects in the session map and access it from the other class. Here is how we can create class that gives singleton instance of session map.</p>
<p><code><br />
import java.util.HashMap;<br />
public class SessionFactory {</p>
<p>private static HashMap session;<br />
private SessionFactory(){<br />
}</p>
<p>public static HashMap getSessionInstance(){<br />
if(session==null){<br />
session = new HashMap();<br />
}</p>
<p>return session;<br />
}</p>
<p>}</p>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=58&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/06/30/easy-data-access-in-pages-of-gwtswing-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>
	</item>
		<item>
		<title>Decorator Pattern Explained</title>
		<link>http://ooerabegins.wordpress.com/2009/06/11/decorator_pattern_explained/</link>
		<comments>http://ooerabegins.wordpress.com/2009/06/11/decorator_pattern_explained/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 04:26:42 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[Objectville]]></category>
		<category><![CDATA[Decorator Pattern]]></category>
		<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=51</guid>
		<description><![CDATA[In last post, we identified what issues can arise if we keep going with the design shown in Etymology Of Decorator Pattern. Lets take a quick look at what fundamental design problems exists in this design. Here, we are hard-coding toppings of Pizza. Which are, in fact, individual Object in the real world. So in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=51&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In last post, we identified what issues can arise if we keep going with the design shown in <a href="http://ooerabegins.wordpress.com/2009/06/02/etymology-of-decorator-pattern/">Etymology Of Decorator Pattern</a>. Lets take a quick look at what fundamental design problems exists in this design.</p>
<div id="attachment_53" class="wp-caption aligncenter" style="width: 202px"><img class="size-full wp-image-53" title="Hierarchy_food2" src="http://ooerabegins.files.wordpress.com/2009/06/hierarchy_food2.png?w=192&#038;h=350" alt="Exsisting Class Hierarchy" width="192" height="350" /><p class="wp-caption-text">Exsisting Class Hierarchy</p></div>
<p>Here, we are hard-coding toppings of Pizza. Which are, in fact, individual Object  in the real world. So in a way, they are <strong>Add-on objects</strong> that can be used to decorate our pizza. If we want to add new item as toppings, we need to modify the class. Ideally, we should be able to add any new topping “without modifying the class”, hence we come to know <strong>Open-closed principal</strong>.</p>
<p><em>“Classes should be closed for modification and open for enhancement.”</em></p>
<p>Now question is how to achieve this. Let’s note down what approach we need to follow to get maximum flexibility in design (maximum in terms of toppings and calculating its cost) in creating one <strong>FreshVeggiePizza with Paneer and Olives</strong>.<br />
1.	Take plain Pizza object.<br />
2.	Decorate it with Paneer.<br />
3.	Decorate it with Olives.<br />
4.	Call cost() method, which will be delegated to “Add-on” or “Decorator” objects also to add up their cost.</p>
<p>Here is the diagram that will clarify exactly how the cost will be calculated for this pizza.</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-55" title="Cost" src="http://ooerabegins.files.wordpress.com/2009/06/cost1.png?w=450&#038;h=300" alt="Cost Of FreshVeggiePizza With Paneer &amp; Olives" width="450" height="300" /><p class="wp-caption-text">Cost Of FreshVeggiePizza With Paneer &amp; Olives</p></div>
<p>There is one important point in this diagram if you noticed. There has to be cost() method in each “Decorator” object as well  as “FreshVeggiePizza”. So we will create one super class “Decorator” for each topping item. Food class will have cost() and getDescription() methods. In addition to that, we should be able to print description of the food according to what toppings are added, rather than tucking description into Pizza class.</p>
<div id="attachment_56" class="wp-caption aligncenter" style="width: 531px"><img class="size-full wp-image-56" title="Decorator Pattern" src="http://ooerabegins.files.wordpress.com/2009/06/decoratorpatter.png?w=521&#038;h=415" alt="Class Design With Decorator Pattern" width="521" height="415" /><p class="wp-caption-text">Class Design With Decorator Pattern</p></div>
<p>Here is the example to realize this diagram.<br />
<code><br />
public abstract class Food {<br />
String description;<br />
public String getDescription(){<br />
return description;<br />
}<br />
public abstract void cost();<br />
}<br />
public abstract class Decorator extends Food {<br />
public abstract String getDescription();<br />
public abstract void cost();<br />
}<br />
public class FreshVeggiePizza extends Food {<br />
public FreshVeggiePizza(){<br />
description = “Fresh Veggie Pizza”;<br />
}</code></p>
<p>public double cost(){<br />
return 100;<br />
}}<br />
public class Paneer extends Decorator {<br />
Food food;<br />
public Paneer(Food food){<br />
this.food = food;<br />
}</p>
<p>public String getDescription(){<br />
return food.getDescription + “, with Paneer”;<br />
}</p>
<p>public double cost(){<br />
return food.cost() + 15;<br />
}<br />
}</p>
<p>Let’s take a look at what happens in this code. Here our “Non-decorator” food will return description set in the constructor.  So we have default implementation of getDescription() in Food class. We want to enforce each Decorator to implement getDescription() method in such a way so that it also reflects object it is decorating. So we have getDescription() method abstract in Decorator class. Now, Decorator classes like Paneer also needs to know which food it is decorating, so we need to pass the decorated food in the constructor of Paneer. In this way, we can create our other pizza and sandwich classes and their decorators.</p>
<p><strong>Recipe Of FreshVeggiePizza with Paneer and Olive :</strong></p>
<p>1.  Create classic FreshVeggiePizza.<br />
Food pizza = new FreshVeggiePizza();<br />
2.	Put a  layer of Paneer over it.<br />
pizza= new Paneer(food);<br />
3.	Spread some olives over pizza.<br />
pizza = new Olive(pizza);</p>
<p>Your FreshVeggiePizza with paneer and olives is ready. Now if you print price of the pizza, it will calculate cost for FreshVeggiePizza + cost of Paneer + cost of Olive. This is the fair level of dynamism that we can expect at this stage of Objectville.</p>
<p><strong>Open-closed Principal Achieved:</strong></p>
<p>We don’t need to change our Pizza class at all to add toppings on it that may change cost of the pizza. We don’t care if cost of paneer or olive booms, because we can parameterize those attributes and it is “decorated” over pizzas rather than tightly coupling it into pizza.</p>
<p><strong>Decorators In Practice :</strong></p>
<p>To take a look at real life decorators, have an eye over java.io classes. Replace Food with <em>InputStream</em>, Decorator with <em>FilterInputStream</em>, FreshVeggiePizza with <em>FileInputStream/ByteArrayInputStream/StringBufferInputStream</em> and Paneer with <em>PushbackInputStream/BufferedInputStream/DataInputStream</em>.</p>
<p><strong>Summary:</strong></p>
<p>Identify properties and methods common to decorators and client components (in our case, client is Pizza).  Create super class for these common methods. Create Decorator super-class and identify methods which need to be implemented by each decorator. Pass reference of client in each decorator to allow decorator to add its own properties. Hence, job of decorator is to extend behavior of client and that too without modifying existing code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=51&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/06/11/decorator_pattern_explained/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/06/hierarchy_food2.png" medium="image">
			<media:title type="html">Hierarchy_food2</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/06/cost1.png" medium="image">
			<media:title type="html">Cost</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/06/decoratorpatter.png" medium="image">
			<media:title type="html">Decorator Pattern</media:title>
		</media:content>
	</item>
		<item>
		<title>Etymology Of Decorator Pattern</title>
		<link>http://ooerabegins.wordpress.com/2009/06/02/etymology-of-decorator-pattern/</link>
		<comments>http://ooerabegins.wordpress.com/2009/06/02/etymology-of-decorator-pattern/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 19:20:13 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[Objectville]]></category>
		<category><![CDATA[Decorator Pattern]]></category>
		<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=39</guid>
		<description><![CDATA[Today our purpose is to know why decorator pattern. In last post, we found that there is class explosion if we go with the first trial. Now what we can do to improve this design is, we can have one abstract super-class Food which will be specialized by Pizza and Sandwich classes. Food class will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=39&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today our purpose is to know why <strong>decorator pattern</strong>. In last post, we found that there is class explosion if we go with the first trial. Now what we can do to improve this design is, we can have one abstract super-class <strong>Food </strong>which will be specialized by <strong>Pizza </strong>and <strong>Sandwich </strong>classes.  Food class will be <em>abstract</em>:</p>
<p><code><br />
public abstract class Food {<br />
private List ingredients;<br />
private String description;<br />
public abstract double cost();<br />
}<br />
</code></p>
<p><strong>Pizza </strong>class will extend this <strong>Food </strong>class and add pizza specific property in this class. For example, crustType, extraCheese, olives, jalapano, paneer etc. If the pizza subclass needs to add jalapano in the toppings, value of jalapano will be true.  Similarly, we can have <strong>Sandwich</strong> class, extending Foot class and adding some Sandwich specific properties to it. Then we can have subclasses like ItalianPizza, DoubleCheesePizza, FreshVeggiePizza subclasses that extend Pizza and will have implementation of cost() method(by overriding). By this approach, we no more need to create separate classes for ItalianPizza with olives, with Paneer etc. Here is the class diagram for this.</p>
<div id="attachment_40" class="wp-caption aligncenter" style="width: 673px"><img class="size-full wp-image-40" title="hierarchy_food" src="http://ooerabegins.files.wordpress.com/2009/06/hierarchy_food.jpg?w=663&#038;h=333" alt="Revised Class-diagram" width="663" height="333" /><p class="wp-caption-text">Revised Class-diagram</p></div>
<p>Let’s check out how it works. When we create instance of, say ItalianPizza, then we can set jalapano, olives true or false according to what we want in the toppings of the pizza. Using the same properties we can calculate cost of the Pizza.</p>
<p>It’s now time to check out what issues can arise in this approach.<br />
1.	What should we do if price of cheese goes up? Here, we are hard-coding price of cheese in cost() method.<br />
2.	What if some new item is introduced for toppings? For example, corn.<br />
3.	What if double cheese is required.</p>
<p>Oh god… save me now… <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Its not going any where near how we want it to be. Next time, we will eliminate these all the issue by introducing one well-known <em>decorator pattern</em>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=39&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/06/02/etymology-of-decorator-pattern/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/06/hierarchy_food.jpg" medium="image">
			<media:title type="html">hierarchy_food</media:title>
		</media:content>
	</item>
		<item>
		<title>First Trial To Objectize Objectville</title>
		<link>http://ooerabegins.wordpress.com/2009/05/31/first_trial_to_objectize/</link>
		<comments>http://ooerabegins.wordpress.com/2009/05/31/first_trial_to_objectize/#comments</comments>
		<pubDate>Sun, 31 May 2009 19:22:58 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[Objectville]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=34</guid>
		<description><![CDATA[We have our small menu ready now, we know what all we are going to serve in Objectville. Oops, it may seem strange if you are new here in Objectville. New readers, just have a look at New Restaurant In Town and continue here. Lets prepare class for each item Classes we need to create: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=34&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have our small menu ready now, we know what all we are going to serve in <em>Objectville</em>. Oops, it may seem strange if you are new here in <em>Objectville</em>. New readers, just have a look at New Restaurant In Town and continue here. Lets prepare class for each item<br />
Classes  we need to create:</p>
<ul> DoubleCheesePizza<br />
ItalianPizza<br />
FreshVeggiePizza<br />
Vegetable Sandwich<br />
Cheese Sandwich<br />
Aalu-matar Sandwich</ul>
<p>We also need to take care of our ordering system in hotel so we need one attribute called “cost” in all of the above classes. We will have descriptions of each item. Keeping in mind likings of customers, we need to have thin crust pizzas, as well as thick crust pizza. So lets have a look at these classes.</p>
<p><code>public class DoubleCheesePizza {<br />
private List ingredients;<br />
private String description;<br />
private String crustType; // Thin crust or thick crust<br />
private String size; // Small, Medium or Large</code></p>
<p>public doublecost() {<br />
// Calculate Cost For DoubleCheesePizza<br />
}<br />
// Other getters and setters</p>
<p>}</p>
<p>Here we have ingredients for printing purpose and we have cost() method in each class, which will calculate cost of item based on its attributes e.g. crustType, size etc.</p>
<p>Similarly, we will have <em>FreshVeggiePizza </em>and <em>ItalianPizza</em>. But being in Gujarat, we need to remember Jains also  so we will include one additional boolean attribute &#8220;withOnion&#8221;, so that we can have it true or false.  We can also have provision to have grated cheese or liquid cheese. We will need a boolean for &#8220;liquidCheese&#8221;.</p>
<p>CheeseSandwich class can be like this:</p>
<p><code>public class CheeseSandwich {<br />
private String name;<br />
private String description;<br />
private List ingredients;<br />
private boolean withExtraCheese;</code></p>
<p>public double cost() {<br />
// Calculate Cost For DoubleCheesePizza<br />
}<br />
// Other getters and setters<br />
}<br />
Remember, we need to add many more items in our menu as Objectville gets popular. So just imagine a scenario when Objectville will be among the most popular restaurants. Customers will definitely expect flexibilities like have some extra cheese in pizza, have some customized toppings like jalapano and olives in freshVeggie. Exclude capsicum from Italian pizza, have “grilled” vegetable sandwich, have some cheese on Aaloo-matar sandwich. And cost is going to vary according to toppings used. If we go with this same design, we will end up with something like this.</p>
<div id="attachment_35" class="wp-caption aligncenter" style="width: 519px"><img class="size-full wp-image-35" title="ClassExplosion" src="http://ooerabegins.files.wordpress.com/2009/05/classexplosion.png?w=509&#038;h=306" alt="Class Explosion" width="509" height="306" /><p class="wp-caption-text">Class Explosion</p></div>
<p>So one problem we see clearly here is explosion of classes. We need to create a class for every customization in the item. May it be some single addition in topping or some different method in cooking. The other problem here is, our cost() method becomes tightly coupled. What will we do if price of cheese goes up.</p>
<p>This design really seems like stupid, when we are well equipped with power of inheritance, polymorphism &amp; aggregation. This is kind of class design that we really don’t want. We will try to get rid of these issues next time.</p>
<p><a href="../2009/06/02/etymology-of-decorator-pattern/" target="_blank">Next&gt;&gt;</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=34&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/05/31/first_trial_to_objectize/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/05/classexplosion.png" medium="image">
			<media:title type="html">ClassExplosion</media:title>
		</media:content>
	</item>
		<item>
		<title>New Restaurant In Town</title>
		<link>http://ooerabegins.wordpress.com/2009/05/30/new-restaurant-objectville/</link>
		<comments>http://ooerabegins.wordpress.com/2009/05/30/new-restaurant-objectville/#comments</comments>
		<pubDate>Sat, 30 May 2009 01:50:04 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[Objectville]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=27</guid>
		<description><![CDATA[Hi again, After thinking for quite a while for what to post in the blog, I thought its not bad to go in Kathy&#8217;s way. If you didn&#8217;t ever try then just have on eye on any book of Kathy Sierra or you can say synonym of Kathy is &#8220;Head First&#8221; books. Just google out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=27&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi again,</p>
<p>After thinking for quite a while for what to post in the blog, I thought its not bad to go in Kathy&#8217;s way. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you didn&#8217;t ever try then just have on eye on any book of Kathy Sierra or you can say synonym of Kathy is &#8220;Head First&#8221; books. Just google out any of the &#8220;Head First&#8221; book and you will surely get &#8220;never read before&#8221; books. </p>
<p>So I finally decided that I will open one restaurant <em>Objectville </em>soon. But to make <em>Objectville </em> rock in the town, we will be serving very few fastfood only in the initial stage, however, we want to go long way so we need system with strong architecture. But we don&#8217;t even want to increase complexity of the system unnecessarily by just piling up different patterns without thinking whether its needed. So I would like to start off will very simple, &#8216;anti-object-oriented&#8217; kind of design, will check out the issues that arises and then recover. And don&#8217;t worry.. There are still few days to go in inauguration of Objectville restaurant so possible redesign won&#8217;t cost too much.  </p>
<p>Here is the menu that we are going to offer initially.<br />
1	Double -cheese Pizza – will have bunch of delicious liquid cheese on top of thick crust<br />
2	Italian Pizza – will have Mozzarella cheese along with tomato sauce with sweet basils and oregano on  top of crusty Italian bread<br />
3	Fresh-veggie Pizza – brimming over with capsicum and crunchy onions.<br />
4	Vegetable Sandwich – prepared and served fresh with crispy capsicum, fresh tomato and our<br />
	spicy green chutney in bread slices.<br />
5	Cheese Sandwich – grated cheese stuffed inside breads with aroma of garlic in it<br />
6	“Aalu-matar” Sandwich – typical Indian style piping hot sandwich stuffed with potatoes and peas cooked.</p>
<p>We will surely have classes of these items which we will see in the next post and will also think of what else we can offer initially to make Objectville rock. So next time, we will design “anti-object-oriented” classes for our restaurant. Remember, descriptions of these item will come into picture later. Discussion point of view,  will try to be programming language independent as much as possible except the code snippets. </p>
<p>I appreciate your time to leave feedback and help me learn and improve Objectville.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=27&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/05/30/new-restaurant-objectville/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>
	</item>
		<item>
		<title>HMVC Pattern For GUI Of Swing/GWT/Desktop Application</title>
		<link>http://ooerabegins.wordpress.com/2009/05/29/hmvc-pattern1/</link>
		<comments>http://ooerabegins.wordpress.com/2009/05/29/hmvc-pattern1/#comments</comments>
		<pubDate>Fri, 29 May 2009 03:21:03 +0000</pubDate>
		<dc:creator>vishalshukla304</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[Desktop Application]]></category>
		<category><![CDATA[GUI Pattern]]></category>
		<category><![CDATA[GWT Design Pattern]]></category>
		<category><![CDATA[GWT Pattern]]></category>
		<category><![CDATA[Hierarchical Model View Controller]]></category>
		<category><![CDATA[HMVC]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://ooerabegins.wordpress.com/?p=6</guid>
		<description><![CDATA[Why Pattern? When developing client tier of application using html,  there are certain limitations in using patterns because code is going to be in xml so while developing Swing/GWT/Desktop application&#8217;s GUI, we have support of Inheritance, Polymorphism and other constructs of language, so in this world, we can play around with patterns, so if we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=6&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Why Pattern?</strong></p>
<p>When developing client tier of application using html,  there are certain limitations in using patterns because code is going to be in xml so while developing Swing/GWT/Desktop application&#8217;s GUI, we have support of Inheritance, Polymorphism and other constructs of language, so in this world, we can play around with patterns, so if we use patterns properly, reusability can make our life easier and it may get worst if not used properly.</p>
<p><strong>HMVC(Hierarhcical Model View Controller) Introduced:</strong></p>
<p>HMVC can be seen as extended version of MVC pattern. We can divide our GUI into different GUI objects some of which will be for navigation purpose (Menubar), some for displaying/editing data(Grid/Tree/Forms) and others may be use for just layouting purpose. So we clearly identify three major aspect of GUI objects.</p>
<ol>
<li>Layouting &#8211; It is taken care by <em>View</em> in HMVC.</li>
<li>Handling user interactions &#8211; Its <em>Controller</em>&#8216;s responsibility.</li>
<li>Server Interactions And Hold Data Being Displayed &#8211; <em>Model </em>handles this.</li>
</ol>
<p>In HMVC, we assign dedicated <em>Controller</em> and <em>Model</em> for each of these objects. It is not necessary to provide each of the GUI object its own controller and model. To keep it simple, we can give dedicated controllers and models only to all the Pages, Grid, Dynamic Tree and other major navigation areas e.g. ContentPanel.</p>
<p><strong>Getting In Depth Of <span style="text-decoration:underline;">H-M-V-C:</span></strong><span style="text-decoration:underline;"><em> </em></span>In MVC architecture, View can only interact with Controller directly and  Controller can communicate with its associated model. Direct communication between View and Model is not possible. Hence <em>View </em>and <em>Model </em>will have references to Controller only and <em>Controller </em>will have access to associated <em>Model </em>and <em>View</em>. In addition to this, Controller will also have ParentController associated with it, which we will see in detail later. When we create new instance of <em>View</em> its associated Controller and Model should be instantiated, we will call this Model-View-Controller set as <strong><em>Triad</em></strong>. Inter-layer communication  is possible only through ApplicationEvents. AppEvent has its <em>type </em>and <em>name</em>. Event type can be NAVIGATION_EVENT, DATA_REQUEST_EVENT or REFRESH_VIEW. One thing to always keep in mind is each triad/controller knows and handles only those events that it is responsible for. For example, &#8220;Login&#8221; triad knows only how to log-in user.</p>
<p>NAVIGATION_EVENT: Navigation event is initiated from View, from where it is passed to controller. Controller checks whether it can handle the event or not. If not, then using chain of responsibility pattern is applied and event is passed through hierarchy of its parent controllers. And when the first controller which can handle the event is found, this hierarchy is stopped.</p>
<p>DATA_REQUEST_EVENT: Data Request Event is one which has server communication involved. This is init. from view, and after being delegated by controller its finally handled by Model which does client&#8217; interaction. After response from server, model fires NAVIGATION or REFRESH_VIEW event to controller to show new page/ refresh data that was requested.</p>
<ol>
<li><strong>View: </strong>View has dedicated role for lay-outing the GUI, applying css classes to the components and fireEvents to the controllers when user interaction takes place. As stated earlier, we can divide screen into GUI objects and certain criterias to give it dedicated controller &amp; model can be complexity in the object, amount of navigation inside the panel or amount of data that needs to be transferred with server and frequency of these transfers. Each view will have acces to its child panels. For example, consider diagram below which shows components of &#8220;ExamplePage&#8221;  in which page is divided into Header, Menubar, NavigationPanel, Preview panel etc. UI object that have dedicated controller and model are outlined in Red. We will name 3 triads in this page as pageTriad, contentTriad, innerNavigationTriad and repectively we can call controllers of  them as pageController, contentController and innerNavigationController.
<div id="attachment_14" class="wp-caption aligncenter" style="width: 469px"><img class="size-full wp-image-14" title="img" src="http://ooerabegins.files.wordpress.com/2009/05/img2.png?w=459&#038;h=348" alt="&quot;ExamplePage&quot; Components" width="459" height="348" /><p class="wp-caption-text">&quot;ExamplePage&quot; Components</p></div></li>
<li><strong>Controller: </strong>Controller&#8217;s main responsibility is to delegate events to view/model/parent controller and synchronizing data between view and model. As discussed earlier, controller has associated parentController. For example, consider example above, in which case, parentController of &#8220;contentController&#8221; is set to &#8220;pageController&#8221;, parent of &#8220;innerNavigationController&#8221; is set to &#8220;contentController&#8221;. Here PageTriad can handle events fired from Menu bar only, ContentTriad can handle events fired from NavigationPanel and it can update preview panel accordingly, InnerNavigationTriad can handle updation in InnerPreviewPanel, however, if there is any event inside &#8220;InnerNavigationPanel&#8221; to update &#8220;PreviewPanel&#8221; outside InnerTriad, then chain of responsibility comes into play. InnerNavigationController can not handle this event, so it passes this event to parent controller &#8211; &#8220;AdminController&#8221; which can handle updation in &#8220;PreviewPanel&#8221;. Here is the diagram to understand hierarchy of triads and how they are associated.
<p><div id="attachment_15" class="wp-caption aligncenter" style="width: 453px"><img class="size-full wp-image-15" title="hmvcLayers" src="http://ooerabegins.files.wordpress.com/2009/05/hmvclayers1.png?w=443&#038;h=275" alt="HMVC Layers " width="443" height="275" /><p class="wp-caption-text">HMVC Layers </p></div>
<p>When dataRequestEvent is fired from view, controller has fixed set to steps to do (1) Get data from view and set it to model and (2) Delegate event to model. As we know what we need to do, we can code this in the super-class of controller in following way.<code><br />
public abstract class Controller{<br />
View view;<br />
Model model;<br />
public void handleEvent(AppEvent event){<br />
if(event.getType.equals("DATA_REQUEST_EVENT")){<br />
setModelData();<br />
model.handleEvent();<br />
}<br />
}<br />
public abstract void setModelData();<br />
public abstract void setViewData();<br />
// getters and setters of view and model<br />
}<br />
</code>Here, setModelData() will be abstract method in the super class of Controller. Our all other controller will extend this Controller class. For Example, lets see what if we want to create &#8220;Login&#8221; widget&#8217;s controller. Its setModelData() method would be somewhat like this.<code><br />
public void setModelData(){<br />
model.setUserName(view.getUserNameTF().getText());<br />
model.setPassword(view.getPasswordTF().getText());<br />
}<br />
</code>Similarly, we can write setViewData() method which will synch data of view with model.  After server response is received, model will fire REFRESH_VIEW event to controller and controller can call setViewData() to synch view and then call refreshView() method to actually update view in screen.</li>
<li><strong>Model:</strong> Model is responsible to hold data that is displayed in view, communicate with server to get latest data and after server response, fire REFRESH_VIEW or NAVIGATION event on controller.</li>
</ol>
<p>Here is the class diagram that may help to implement this pattern and identifying what interface each layer needs to provide to communicate with other layer.</p>
<div id="attachment_16" class="wp-caption aligncenter" style="width: 519px"><img class="size-full wp-image-16" title="EADiagram" src="http://ooerabegins.files.wordpress.com/2009/05/eadiagram1.png?w=509&#038;h=312" alt="HMVC - Class Diagram" width="509" height="312" /><p class="wp-caption-text">HMVC - Class Diagram</p></div>
<p>Summarizing the pattern, complex UI objects are given dedicated controllers and model that communicate with each other through events. DataRequestEvent go from View-&gt;Controller-&gt;Model-&gt;Server-&gt;Model-&gt;Controller-&gt;refreshView() and Navigation events are handled by controller using chain of responsibility. When the first controller that can handle the event is found, chain ends.</p>
<p>After this initial framework is build, it becomes too easy to add new components later or debug existing component and we can also build super classes for each type of UI component for example Page, Grid or Tree. Will get into details of those in coming posts.</p>
<p><strong>References:</strong><br />
<a href="http://www.javaworld.com/javaworld/jw-07-2000/jw-0721-hmvc.html?page=1">Javaworld HMVC Tutorial</a><br />
<a href="http://www.thecentric.com/wiki/index.php/HMVC_Tutorial">The Centric HMVC Tutorial</a></p>
<p>Suggetions and queries are always welcome. Email me at vishal1shukla2@gmail.com.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ooerabegins.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ooerabegins.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ooerabegins.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ooerabegins.wordpress.com&amp;blog=7900685&amp;post=6&amp;subd=ooerabegins&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ooerabegins.wordpress.com/2009/05/29/hmvc-pattern1/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c0bfd0c07a7a1622b81927a76c2719b0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vishalshukla304</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/05/img2.png" medium="image">
			<media:title type="html">img</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/05/hmvclayers1.png" medium="image">
			<media:title type="html">hmvcLayers</media:title>
		</media:content>

		<media:content url="http://ooerabegins.files.wordpress.com/2009/05/eadiagram1.png" medium="image">
			<media:title type="html">EADiagram</media:title>
		</media:content>
	</item>
	</channel>
</rss>
