<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
    <title>Nerdic Canvass</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/NerdicCanvass/Atom.aspx" />
    <subtitle type="html"> Learn.Develop.Share</subtitle>
    <id>http://geekswithblogs.net/NerdicCanvass/Default.aspx</id>
    <author>
        <name>Sanket Naik</name>
        <uri>http://geekswithblogs.net/NerdicCanvass/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2010-09-01T11:58:48Z</updated>
    <entry>
        <title>Events vis-a-vis Delegates</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/NerdicCanvass/archive/2010/08/30/events-vis-a-vis-delegates.aspx" />
        <id>http://geekswithblogs.net/NerdicCanvass/archive/2010/08/30/events-vis-a-vis-delegates.aspx</id>
        <published>2010-08-30T15:25:0005:30:00</published>
        <updated>2010-09-01T11:20:28Z</updated>
        <summary type="html">Examination of why Events vs Delegates</summary>
        <content type="html">&lt;p&gt;Recently, I was involved in a hiring process. And of the many questions that were asked to the candidates during the process, one common question that was asked a lot was:&lt;/p&gt;
&lt;p&gt;Difference between Events and Delegates ? And most of the time, i don’t get what I really expect. The essential question, that I am trying to get is,&lt;/p&gt;
&lt;p&gt;If I can achieve the same functionality with an delegate, that I desire from an event, and more over the underlying mechanism of the event is a delegate, why has the event keyword been created by Microsoft ?&lt;/p&gt;
&lt;p&gt;Lets look at an example Delegate:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_2.png"&gt;&lt;img title="image" border="0" alt="image" width="504" height="256" style="border-bottom: 0px; border-left: 0px; margin: 1px 2px; display: inline; border-top: 0px; border-right: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This gets converted to something like the following:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_4.png"&gt;&lt;img title="image" border="0" alt="image" width="358" height="301" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb_1.png" /&gt;&lt;/a&gt;   &lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_6.png"&gt;&lt;img title="image" border="0" alt="image" width="474" height="167" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb_2.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Interesting enough, not yet, lets complete the picture after throwing in an event.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_8.png"&gt;&lt;img title="image" border="0" alt="image" width="506" height="315" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb_3.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let’s examine the class, DelegateInspector, in reflector.&lt;/p&gt;
&lt;p&gt; &lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_10.png"&gt;&lt;img title="image" border="0" alt="image" width="803" height="539" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb_4.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What’s just happened, just the event declaration generates quite some amount of code around. Now what is the implication of the code above is below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_12.png"&gt;&lt;img title="image" border="0" alt="image" width="1049" height="364" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://geekswithblogs.net/images/geekswithblogs_net/NerdicCanvass/WindowsLiveWriter/EventsvisavisDelegates_122EF/image_thumb_5.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope it helps!&lt;/p&gt;&lt;img src="http://geekswithblogs.net/NerdicCanvass/aggbug/141549.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/NerdicCanvass/comments/141549.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/NerdicCanvass/comments/commentRss/141549.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/NerdicCanvass/services/trackbacks/141549.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Welcome Back !!!</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/NerdicCanvass/archive/2010/03/29/welcome-back-again.aspx" />
        <id>http://geekswithblogs.net/NerdicCanvass/archive/2010/03/29/welcome-back-again.aspx</id>
        <published>2010-03-29T16:19:2605:30:00</published>
        <updated>2010-03-29T16:19:26Z</updated>
        <content type="html">&lt;p&gt;Well, its been quite sometime since I have been able to post anything significant.Have been quite busy with some personal stuff, which required more immediate attention. Finally, got the time today to log about something.&lt;/p&gt;
&lt;p&gt;I have switched companies, I have been cussed about and world seems to have gone awry to awesome for me in the meanwhile.&lt;/p&gt;
&lt;p&gt;Any ways, back to my blogging ways again and soon I would be starting a series of blogs about WCF, and Networking stuff.&lt;/p&gt;
&lt;p&gt;Till Then,&lt;/p&gt;
&lt;p&gt;- Happy Coding!&lt;/p&gt;&lt;img src="http://geekswithblogs.net/NerdicCanvass/aggbug/138969.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/NerdicCanvass/comments/138969.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/NerdicCanvass/comments/commentRss/138969.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/NerdicCanvass/services/trackbacks/138969.aspx</trackback:ping>
    </entry>
    <entry>
        <title>My tryst with MAPI</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/NerdicCanvass/archive/2009/12/07/my-tryst-with-mapi.aspx" />
        <id>http://geekswithblogs.net/NerdicCanvass/archive/2009/12/07/my-tryst-with-mapi.aspx</id>
        <published>2009-12-07T12:35:0305:30:00</published>
        <updated>2009-12-07T12:35:03Z</updated>
        <content type="html">&lt;p&gt;For the past two weeks I was up against MAPI. I must admit, its a amazing piece of work and liked it, the more I delved into it.&lt;/p&gt;
&lt;p&gt;Let me delve a bit more into the specifics of the problem a bit more.&lt;/p&gt;
&lt;p&gt;We have a piece of software, and it is used to synch up contacts across Exchange and a custom application using Mapi Server Client. Now this works fine if the Systems are Exchange Server 2003 on Win2k3, and Our Application is on Windows 2008. But the problem started appearing when we tried the same thing out when the combination is Exchange 2007 on Win2k8 and our application on Win 2k8. &lt;/p&gt;
&lt;p&gt;I dug deep and I resorted to aprroach, the only guy who I knew blogs about MAPI - &lt;a title="SGriffin" href="http://blogs.msdn.com/stephen_griffin/"&gt;SGriffin&lt;/a&gt;. And he did respond and put us on the right track.&lt;/p&gt;
&lt;p&gt;If you face same kind of problems that we faced, the things that you need to check is:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;There is a issue with with IPv6 - &lt;a title="Click Here" href="http://blogs.msdn.com/stephen_griffin/archive/2008/08/15/mapi-and-ipv6.aspx"&gt;Click Here&lt;/a&gt; and &lt;a title="Click Here" href="http://blogs.msdn.com/stephen_griffin/archive/2009/01/28/more-issues-with-mapi-and-ipv6.aspx"&gt;Click Here&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;Ensure that you create the Service Account properly - &lt;a title="Click Here" href="http://exchangeexchange.com/blogs/joel.stidley/archive/2006/12/10/giving-service-account-access-to-all-mailboxes-on-exchange-2007-server.aspx"&gt;Click Here&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;Make sure your user with whom you created your profile is a member of "Exchange Organization Administrator"&lt;/li&gt;
    &lt;li&gt;Ensure you download and install the latest Exchange MAPI server client&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hope this heps.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/NerdicCanvass/aggbug/136803.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/NerdicCanvass/comments/136803.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/NerdicCanvass/comments/commentRss/136803.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/NerdicCanvass/services/trackbacks/136803.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Pattern Discussion: Abstract Factory vis a vis Factory</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/NerdicCanvass/archive/2009/11/12/pattern-discussion-abstract-factory-vis-a-vis-factory.aspx" />
        <id>http://geekswithblogs.net/NerdicCanvass/archive/2009/11/12/pattern-discussion-abstract-factory-vis-a-vis-factory.aspx</id>
        <published>2009-11-12T19:21:5705:30:00</published>
        <updated>2010-08-30T21:08:36Z</updated>
        <content type="html">&lt;p&gt;The other day we had a discussion related to the abstract factory and let me tell you, flames flew and it was high on melodrama.&lt;/p&gt;
&lt;div&gt;Anyways coming back to the main point, the root of whole discussion was,&lt;/div&gt;
&lt;div&gt; &lt;strong&gt;A:&lt;/strong&gt; Why should I use the abstract factory, just for a parallel set of classes, what am I getting out of it ?&lt;/div&gt;
&lt;div&gt; &lt;strong&gt;B:&lt;/strong&gt; You are abstracting your product, that's why you are creating it. Apart from that, its a you have a mechanism for creating  related set of products, which is important here, you see you should not forget that, its for creating a set of related family of products.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;C:&lt;/strong&gt; But say if you are just creating is two set of components, a UI Components for rich mode and the simple mode, could you not do with a static Factory implementation instead of so much of fun fare? And also if you look closely, what you are doing is essentially now binding your classes to the implementation of the Abstract Factories some where, because to get the code running you have to write the Implementation class some where, so would not it be better if we had just a static factory class which gives us what we need.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;B:&lt;/strong&gt; hmmmm...&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;A:&lt;/strong&gt; Apart from that so much of code to manage .... That's a good one C:)&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;C:&lt;/strong&gt; Thanks! Man&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;B:&lt;/strong&gt; Factory Method &lt;em&gt;&lt;font color="#004080"&gt;defines an interface for creating an object, but lets subclasses decide which of those to instantiate. A factory method lets classes defer instantiation&lt;/font&gt; &lt;font color="#004080"&gt;to subclasses&lt;/font&gt;&lt;/em&gt;.By contrast, an Abstract Factory &lt;em&gt;&lt;font color="#004080"&gt;provides an interface for creating families of related or dependent objects without specifying their concrete classes&lt;/font&gt;&lt;/em&gt;.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;C:&lt;/strong&gt; We have a family of related objects but, ... I don't want to take a purists view or go by book view.. I look at convinience and unless you tell me why, I don't see any reason why I should not go for a Factory than a Abstract Factory here.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;A:&lt;/strong&gt; And if you ask me, I guess you are over complicating, is not this kind of an YAGNI.  &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;B:&lt;/strong&gt; Well, let me examine the definitions a bit more:&lt;/div&gt;
&lt;div&gt;Factory Method &lt;em&gt;&lt;font color="#004080"&gt;defines an interface for creating an object, but lets subclasses decide which of those to instantiate. A factory method lets classes defer instantiation&lt;/font&gt; &lt;font color="#004080"&gt;to subclasses&lt;/font&gt;&lt;/em&gt;.&lt;/div&gt;
&lt;div&gt;Which essentially means, in this case the decision is taken by sub class -&amp;gt; Inheritance is in action.&lt;/div&gt;
&lt;div&gt;Abstract Factory &lt;em&gt;&lt;font color="#004080"&gt;provides an interface for creating families of related or dependent objects without specifying their concrete classes&lt;/font&gt;&lt;/em&gt;. Now in this case the job of creating the instance of the products are delegated -&amp;gt; Composition in Action.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;And as you guys already know Composition allows you to delay the creation of back-end objects until (and unless) they are needed, as well as changing the back-end objects dynamically throughout the lifetime of the front-end object. With inheritance, you get the image of the superclass in your subclass object image as soon as the subclass is created, and it remains part of the subclass object throughout the lifetime of the subclass.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;So I would say, if you need it dynamically vary, take the composition route and enjoy the benefits of Abstarct Factory else, Factory should be just fine for you.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;C:&lt;/strong&gt; hmmm..&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;A:&lt;/strong&gt; ok&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Hope you like the dialogue....:)&lt;/div&gt;&lt;img src="http://geekswithblogs.net/NerdicCanvass/aggbug/136242.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/NerdicCanvass/comments/136242.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/NerdicCanvass/comments/commentRss/136242.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/NerdicCanvass/services/trackbacks/136242.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Patterns:Factory</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/NerdicCanvass/archive/2009/11/12/patternsfactory.aspx" />
        <id>http://geekswithblogs.net/NerdicCanvass/archive/2009/11/12/patternsfactory.aspx</id>
        <published>2009-11-12T19:18:3805:30:00</published>
        <updated>2010-08-30T21:08:51Z</updated>
        <content type="html">&lt;div&gt;Since I have already mentioned Factory in a post, its time we should talk about the same. Factory should get the respect it deserves because its worth it.&lt;/div&gt;
&lt;div&gt; &lt;strong&gt;Intent&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;Defines an interface for creating an object, but lets subclasses decide which of those to instantiate.&lt;/div&gt;
&lt;div&gt; &lt;strong&gt;Scenario&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; Say we need to implement a way to create Accounts. Now, there are different kinds of Account,&lt;/div&gt;
&lt;div&gt;a.) Savings Account - Acts as a Normal, but allows you to withdraw only when you are not taking the balance below the minimum stipulated balance.&lt;/div&gt;
&lt;div&gt;a.) i.) Salaried Savings Account - Same as Savings Account but minimum balance can be 0.&lt;/div&gt;
&lt;div&gt;b.) Current Account.&lt;strong&gt;-&lt;/strong&gt; Can allow you to go till a -ve balance, only for traders&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;As you can see, the difference in limit and the difference in Withdrawl Strategies. There are many other business rules, but for the context of the Problem, we would like to keep it simple. But one essential question is, why do we need to think so much, we just need to be able to create Savings Account, Salaried Savings Account and Current Account ?&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Well, the bank says we want to keep a hook for bringing in new types of Account in Near future. There you have it, Business as usual. So how do you structure the code, I can think of, I would create an Account Class, where the Deposit would be having a implementation since, its function is just to add money to the account. But as for the Withdraw method I would leave it as abstract, because, it depends on the type of Account you are operating it. Its a stronger relationship.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;img alt="" width="352" height="253" src="/images/geekswithblogs_net/NerdicCanvass/AccountClassStructure.png" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In this scenarios, we generally prefer the factory pattern where in, if a new type of Account is introduced tommorow, we can easily add a new subclass of the AccountFactory class and bring in support for a new kind of account.
&lt;div&gt; Let me just substantiate, what I just wrote.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;img alt="" width="587" height="435" src="/images/geekswithblogs_net/NerdicCanvass/AccountFactory.png" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;So as you can see from the above diagram, the responsibility of creation of CurrentAccount lies in CurrentAccountFactory and like wise for SavingsAccount the SavingsAccountFactory. Say we introduce a new Account Class we just need to introduce a new AccountFactory subclass which will take care of instantiating it properly.
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;There are two versions of a Factory pattern:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;strong&gt;Static Factory&lt;/strong&gt;. There are no subclasses, rather there is a single static method that takes in a parameter and creates a appropriate instance of the product. This works when the frequency of adding a product is low and it can survive a compilation.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;strong&gt;Instance Factory&lt;/strong&gt;. This generally works in conjunction with Reflection as in Java/.Net. and this works better when the chances of adding a product is high and we do not want to re-compile the whole code base.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;&lt;img src="http://geekswithblogs.net/NerdicCanvass/aggbug/136241.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/NerdicCanvass/comments/136241.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/NerdicCanvass/comments/commentRss/136241.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/NerdicCanvass/services/trackbacks/136241.aspx</trackback:ping>
    </entry>
</feed>
