Using decorator patternhttp://forums.asp.net/t/1780648.aspx/1?+Using+decorator+patternFri, 16 Mar 2012 11:46:10 -040017806484881667http://forums.asp.net/p/1780648/4881667.aspx/1?+Using+decorator+pattern Using decorator pattern <p>Hi guys Check my example below:<br> <br> CrazyBitz is an employment agency specializing in matching IT staff with specific skill sets to the needs of prospective employers. An employer might need someone with a c# background and SQL-server experience, whore also qualified as a CCNA. They need an application that will automatically evaluate how well the skills of applicants match the needs of employers. <br> &nbsp;<br> Outline arguing that this IS or IS NOT a suitable problem to address with the aid of the decorator pattern... <br> &nbsp;<br> I say a decorator pattern will be useful since a person that will be employed can have additional skills other than c# and Sql-server as time goes...<br> <br> What are your personal views about this example?</p> 2012-03-15T11:45:32-04:004881955http://forums.asp.net/p/1780648/4881955.aspx/1?Re+Using+decorator+patternRe: Using decorator pattern <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Anele</h4> I say a decorator pattern will be useful since a person that will be employed can have additional skills other than c# and Sql-server as time goes...<br> <br> </blockquote> <p></p> <p>I'd disagree. it's clear from the initial specification that a potential employee will have a collection of skills, so the initial design should reflect that, and there's absolutely no value in having a Decorator for that.</p> <p>What is likely to change is that different employers might have different ways of evaluating the skills, weighting some over others. In which case there is a possible argument for using the Strategy pattern. And of course, when using the Strategy pattern there is a distinct possibility that you will use the Decorator pattern to wrap/chain the different strategies.</p> <p>But what you should argue with your teacher (I guess this is a homework example, or possibly an interview question) is that applying any patterns at this point is just overcomplicating the system. You're anticipating possible changes&nbsp;in the future, and&nbsp;so it would make no sense in V1 to do any more than the bare minimum. Adding a ton of potential extensibility points,&nbsp;unless clearly required in the spec, is a waste of time and resource. If and when change is required, you can&nbsp;refactor to patterns depending on the change.</p> <p>Remember,&nbsp;if you add&nbsp;&quot;patterns&quot; to code, it increases complexity (in general) and you&nbsp;have to be able to justify that. Not only that, you have to test it and prove&nbsp;the design, which means coming up with concrete examples. So Patterns generally only make sense&nbsp;either when you're deliberately setting out to write extensible code, or when the first change&nbsp;comes along.&nbsp;</p> <p>&nbsp;</p> 2012-03-15T14:25:06-04:004883787http://forums.asp.net/p/1780648/4883787.aspx/1?Re+Using+decorator+patternRe: Using decorator pattern <p></p> <blockquote><span class="icon-blockquote"></span> <h4>DMW</h4> make no sense in V1 to do any more than the bare minimum</blockquote> Am confused by this line specialy V1. So there wont be any objects such as the skills mayneedto be decorated in future? <p></p> <p>&nbsp;</p> 2012-03-16T11:13:15-04:004883817http://forums.asp.net/p/1780648/4883817.aspx/1?Re+Using+decorator+patternRe: Using decorator pattern <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Anele</h4> So there wont be any objects such as the skills mayneedto be decorated in future?</blockquote> <p></p> <p>Firstly, how would you decorate a skill? it is what it is, a skill.</p> <p>But let's play a game for a second.</p> <p>Let's say that in V2 (V1 meant version 1, so V2 is the second version) the client decides that they want to &quot;decorate&quot; the skill, with, say, the length of time that the person has had that skill.</p> <p>So in V1, the requirement was just &quot;Must be able to code in C#&quot;. In version 2, it is &quot;Must have three years experience in C#&quot;.</p> <p>Hmm. Is that a decoration of the skill. I'm not sure that it is. But you could argue that it is a decoration around how we check for the skill.</p> <p>So if in V1 we had a simple check for &quot;Has skill xxx&quot;, we could now decorate that checker with &quot;Has skill for appropriate period of time yyyy&quot;.</p> <p>You will notice that this is what I meant when I said in my previous post</p> <p>&quot;<span>In which case there is a possible argument for using the Strategy pattern. And of course, when using the Strategy pattern there is a distinct possibility that <strong>you will use the Decorator pattern to wrap/chain the different strategies</strong>.&quot;</span></p> <p><span>Now here's the&nbsp;<strong>really, really important bit</strong>.</span></p> <p><span>You're guessing about what future requirements might be. You don't know. You're guessing.</span></p> <p><span>So, should you&nbsp;<strong>in version 1</strong> guess about what might come down the wire in version 2? Or version 3? Or version 4?</span></p> <p><span>Some of the problems with this approach are as follows:</span></p> <ol> <li>Allowing for future extensibility costs time and money. The business sponsor who wants version 1 might not be prepared to wait or pay for that. </li><li>In order to allow for extensibility increases complexity, and that complexity has to be tested and proven at the beginning. </li><li>If you guess, and you guess wrong, then you'll have added a ton of complexity to the code for no good reason. </li></ol> <p><span>Offsetting this is the fact that if change is an expected part of the requirements, and you intend to put this code into systems, especially those written by other teams where making future changes is difficult, then you might well need to design a system that has additional complexity up front. In essence, this is the challenge facing, say, the ASP.NET team, the WPF team and other teams on the .NET Framework, where they know that their code is going to be used and extended by millions of developers. They try really hard to develop extensiblity points into the code so that they can add new features, such as ASP.NET MVC for example, without having any negative impact on all existing ASP.NET applications.</span></p> <p><span>But that costs BIG bucks to get right (well done the ASP.NET team, btw.)</span></p> <p><span>The real development / design skill here is that you need to design and code just enough, and not more. And then when change happens, and it will, adapt the code in such a way that you can make further similar changes without having to completely re-engineer the code.</span></p> <p><span>Hence, in v1 you probably wouldn't use the decorator pattern (there's no need), but that having a separated strategy makes sense both from a testing and an extensibility perspective; but in v2, when you analyse the changes that exist at the time, you might decide that the best approach is to then use a decorator around the existing matching strategy types.</span></p> <p><span>Apologies for the length of the post, and I hope it helps.</span></p> <p></p> 2012-03-16T11:35:57-04:004883834http://forums.asp.net/p/1780648/4883834.aspx/1?Re+Using+decorator+patternRe: Using decorator pattern <p>Hehe...lov it,its more clear now. Thanx Dave<img title="Laughing" border="0" alt="Laughing" src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-laughing.gif"></p> 2012-03-16T11:46:10-04:00