<?xml version="1.0" encoding="utf-8" standalone="no"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><title>thinking out LOUD</title><description>my space for the random things in life</description><managingEditor>noemail@noemail.org (Taher Chhabra)</managingEditor><pubDate>Fri, 23 Nov 2018 16:19:58 GMT</pubDate><generator>Jekyll https://jekyllrb.com/</generator><link>https://taherchhabra.github.io/</link><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:subtitle>my space for the random things in life</itunes:subtitle><itunes:owner><itunes:email>noemail@noemail.org</itunes:email></itunes:owner><item><title>Aspnet Core Identity Setup Without Entityframework</title><link>https://taherchhabra.github.io/blog/aspnet-core-Identity-setup-without-entityFramework</link><category>aspnetcore</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Thu, 22 Sep 2016 12:00:00 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/aspnet-core-Identity-setup-without-entityFramework</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I was trying to setup the new Asp.net Core Identity without Entity framework. Googled a bit and found these stackoverflow answers</p>

<p>http://stackoverflow.com/questions/36095076/custom-authentication-in-asp-net-core http://stackoverflow.com/questions/31271600/asp-net-5-identity-custom-signinmanager http://stackoverflow.com/questions/36184856/authentication-and-authorization-without-entity-framework-in-asp-net-5-mvc-6</p>

<p>All the answers hints at implementing Asp.net Identity Interfaces and making changes in startup.cs. But none of these answers were working for me. Googled a bit more and found <a href="http://stackoverflow.com/questions/36794285/how-to-use-asp-net-core-1-signinmanager-without-entityframework">this</a>. There is a <a href="https://github.com/MatthewKing/IdentityWithoutEF">sample</a> project in the answer which helped a lot even though it doesn’t work with the latest asp.net version. Also after implementing the interfaces using the sample project SignInManager.IsSignedIn(User) method was always returning false. Found the fix <a href="https://github.com/aspnet/Home/issues/1727">here</a></p>

<p>In all you just need to implement IRoleStore, IUserStore and create CustomUser and CustomRole class and add these lines in Startup.cs</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>services.AddSingleton&lt;IUserStore&lt;ApplicationUser&gt;, ExampleUserStore&gt;();
services.AddSingleton&lt;IRoleStore&lt;ApplicationRole&gt;, ExampleRoleStore&gt;();
services.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;().AddDefaultTokenProviders();
</code></pre></div></div>

<p>Here is the working <a href="https://github.com/taherchhabra/AspNetCoreIdentityWithoutEF">sample</a> of Asp.Net core without EF</p>]]></content:encoded><description>I was trying to setup the new Asp.net Core Identity without Entity framework. Googled a bit and found these stackoverflow answers</description></item><item><title>Blogging For The Sake Of Blogging</title><link>https://taherchhabra.github.io/blog/blogging-for-the-sake-of-blogging</link><category>Design Pattern</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Sun, 27 Sep 2015 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/blogging-for-the-sake-of-blogging</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I started my blog in 2011 and wrote couple of posts about software development. My Last blog post was in 2013 and today is 2015. I didn’t blog for last two years. I kept procrastinating and kept feeling guilty. I wanted to blog each time I saw a new technology, new plugin, new framework, new thing which I worked on, on political situation in my country, on corruption, on poverty, on illiteracy and so many other things . But I didn’t do it.</p>

<p>If I make a list of reasons why I didn’t blogged they will be something like</p>
<ol>
  <li>Didn’t had time.</li>
  <li>Didn’t had things to Post</li>
  <li>No readers on my blog</li>
  <li>I am an introvert and don’t like to share much</li>
  <li>What will people think if I write something which they don’t like or don’t agree with.</li>
  <li>Blah Blah Blah.</li>
</ol>

<p>But somewhere I know that the above reasons were not the ones stopping me from blogging. The real reason which was stopping me is “Blogging for the sake of Blogging.”.
I had created this blog not to share my ideas/opinions with the world, but to impress my future employers / to get freelancing clients.
This was part of my resume gardening, Part of my showing to the world that I ‘know this stuff’. I had this blog just for the sake of having a blog and not out of love or interest.</p>

<p>There is nothing wrong if you have a blog for the purpose stated above, but I am a kind of person who does something only if I like doing that. If I do something out of compulsion, I am usually Bad at it.</p>

<p>So from today, I have decided that I will blog not out of compulsion but out of love.
This will not just be a tech blog in a race to post about “new” features of the “new” framework. It will be random blog with random posts. Whatever comes to my mind which I feel worthy enough to share will be shared here. It will be a reflection of my thoughts / Opinions / Life.</p>

<p>Who knows when will be my next post, maybe tomorrow or maybe after a year. but whenever I post next, It will not be to impress someone, It will be for myself</p>]]></content:encoded><description>I started my blog in 2011 and wrote couple of posts about software development. My Last blog post was in 2013 and today is 2015. I didn’t blog for last two years. I kept procrastinating and kept feeling guilty. I wanted to blog each time I saw a new technology, new plugin, new framework, new thing which I worked on, on political situation in my country, on corruption, on poverty, on illiteracy and so many other things . But I didn’t do it.</description></item><item><title>System Threading Timer Doesnt Tick For Some Reason</title><link>https://taherchhabra.github.io/blog/system-threading-timer-doesnt-tick-for-some-reason</link><category>timer</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Mon, 12 Mar 2012 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/system-threading-timer-doesnt-tick-for-some-reason</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Today, I was working on program where in it had to send a string message over a socket after a particular interval. So i thought of using Timer. After searching on the internet i found there are two timers in. Net. System.Timers.Timer and System.Threading.timer.
The difference between the two is that system.threading.timer executes the callback method on a different thread.
I went with system.threading.timer as it suited my requirement. But after some testing i found that the timer callback executed 3 to 4 times and suddenly stopped.
After looking here and there and reading documentation on msdn i found that the timer is garbage collected as soon as it goes out of scope. The solution was to keep a reference of the timer throughout the application lifecycle.</p>]]></content:encoded><description>Today, I was working on program where in it had to send a string message over a socket after a particular interval. So i thought of using Timer. After searching on the internet i found there are two timers in. Net. System.Timers.Timer and System.Threading.timer. The difference between the two is that system.threading.timer executes the callback method on a different thread. I went with system.threading.timer as it suited my requirement. But after some testing i found that the timer callback executed 3 to 4 times and suddenly stopped. After looking here and there and reading documentation on msdn i found that the timer is garbage collected as soon as it goes out of scope. The solution was to keep a reference of the timer throughout the application lifecycle.</description></item><item><title>Jquery Event Model</title><link>https://taherchhabra.github.io/blog/jquery-Event-Model</link><category>jquery</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Thu, 10 Nov 2011 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/jquery-Event-Model</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>We all know the difference between a Standards Complaint browser and Internet Explorer. Those quirks are in the Event handling mechanism as well.</p>

<p>This all started when Netscape corporation introduced an event handling model in their Netscape Navigator browser, It was called Netscape Event Model or Basic Event Model but majority of Web Developers know it as DOM Level 0 Event Model.</p>

<p>Then in November 2000 W3C introduced a standardized model for Event handling which is known as DOM level 2 Event Model. All modern browsers support this model except Internet Explorer (As usual) ,IE uses its own proprietary Model.</p>

<p>So lets have a look at these two models before we see how JQuery makes life easier.</p>

<h3 id="dom-level-0-event-model">DOM Level 0 Event model</h3>
<p>In this event model the event handlers are assigned by assigning the reference of the event handler to the corresponding properties of the element</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span> 
<span class="nt">&lt;title&gt;</span>Dom level 0 event model<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-1.4.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span>
<span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> 
     <span class="nx">$</span><span class="p">(</span><span class="s1">'#example'</span><span class="p">)[</span><span class="mi">0</span><span class="p">].</span><span class="nx">onmouseover</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> 
                                         <span class="nx">alert</span><span class="p">(</span><span class="s1">'on mouse over'</span><span class="p">);</span>
                                    <span class="p">};</span>
 <span class="p">});</span> 
<span class="nt">&lt;/script&gt;</span>
<span class="nt">&lt;/head&gt;</span>
<span class="nt">&lt;body&gt;</span>
<span class="nt">&lt;img</span> <span class="na">id=</span><span class="s">"example"</span> <span class="na">src=</span><span class="s">"test.jpg"</span> <span class="na">height=</span><span class="s">"500px"</span> <span class="na">width=</span><span class="s">"500px"</span><span class="nt">&gt;</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>In the above code we are assigning the onmouse event handler code to the onmouseover property of the image element</p>

<h3 id="dom-level-2-event-model">DOM Level 2 Event model</h3>

<p>The disadvantage of DOM Level 0 event model was that, only one event handler can be attached for an event. Since the event handler are referenced by the properties only one handler can be አስስግነድ</p>

<p>In the above code if we write these two statements</p>

<p>$(‘#example’)[0].onmouseover = function(event) { alert(‘first mouse over’); };</p>

<p>$(‘#example’)[0].onmouseover = function(event) { alert(‘second mouse over’); };</p>

<p>The first event handler will be replaced with the second event handler. So in DOM Level 2 Event Model there is a method addEventListener(eventType,listener,useCapture).</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span>
<span class="nt">&lt;title&gt;</span>Dom level 0 event model<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-1.4.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span>
<span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> 
     <span class="kd">var</span> <span class="nx">element</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">'#example'</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span> 
     <span class="nx">element</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> <span class="nx">alert</span><span class="p">(</span><span class="s1">'BOOM !'</span><span class="p">);</span> <span class="p">},</span><span class="kc">false</span><span class="p">);</span> <span class="p">});</span> 
<span class="nt">&lt;/script&gt;</span> 
<span class="nt">&lt;/head&gt;</span> 
<span class="nt">&lt;body&gt;</span> 
<span class="nt">&lt;img</span> <span class="na">id=</span><span class="s">"example"</span> <span class="na">src=</span><span class="s">"test.jpg"</span> <span class="na">height=</span><span class="s">"500px"</span> <span class="na">width=</span><span class="s">"500px"</span><span class="nt">&gt;</span> 
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<h3 id="internet-explorer-event-model">Internet Explorer Event Model</h3>

<p>Instead of addEventListener method, Internet Explorer event Model uses attachEvent method having the following signature attachEvent(eventName,handler)</p>

<h3 id="jquery-event-model">JQuery Event Model</h3>

<p>Jquery’s event model provides a unified api for different browsers. It allows multiple handler for a event and makes Event instance available as parameter to the handlers</p>

<p>In JQuery, we can establish event handlers on DOM elements using the bind method.</p>

<p>bind(eventType,data,handler)</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span>
<span class="nt">&lt;title&gt;</span>Dom level 0 event model<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-1.4.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span> 
<span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> 
<span class="kd">var</span> <span class="nx">element</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">'#example'</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span>
<span class="nx">element</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">'on click!'</span><span class="p">);})</span> <span class="p">});</span> 
<span class="nt">&lt;/script&gt;</span>
<span class="nt">&lt;/head&gt;</span>
<span class="nt">&lt;body&gt;</span>
<span class="nt">&lt;img</span> <span class="na">id=</span><span class="s">"example"</span> <span class="na">src=</span><span class="s">"test.jpg"</span> <span class="na">height=</span><span class="s">"500px"</span> <span class="na">width=</span><span class="s">"500px"</span><span class="nt">&gt;</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>you can chain multiple events as shown below</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;head&gt;</span>
<span class="nt">&lt;title&gt;</span>Dom level 0 event model<span class="nt">&lt;/title&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-1.4.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
<span class="nt">&lt;script </span><span class="na">type=</span><span class="s">"text/javascript"</span><span class="nt">&gt;</span>
 <span class="nx">$</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
 <span class="kd">var</span> <span class="nx">element</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">'#example'</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span> 
<span class="nx">element</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">'Boom !'</span><span class="p">);}).</span><span class="nx">bind</span><span class="p">(</span><span class="s1">'click'</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">'Zoom!'</span><span class="p">);})</span> <span class="p">});</span>
<span class="nt">&lt;/script&gt;</span> 
<span class="nt">&lt;/head&gt;</span>
<span class="nt">&lt;body&gt;</span>
<span class="nt">&lt;img</span> <span class="na">id=</span><span class="s">"example"</span> <span class="na">src=</span><span class="s">"test.jpg"</span> <span class="na">height=</span><span class="s">"500px"</span> <span class="na">width=</span><span class="s">"500px"</span><span class="nt">&gt;</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>The Event handlers can be removed using unbind method</p>

<p>unbind(eventType,listener)</p>]]></content:encoded><description>We all know the difference between a Standards Complaint browser and Internet Explorer. Those quirks are in the Event handling mechanism as well.</description></item><item><title>Myth Reference Types Live On Heap Value Types Lives On Stack</title><link>https://taherchhabra.github.io/blog/myth-reference-types-live-on-heap-value-types-lives-on-stack</link><category>myth</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Fri, 7 Oct 2011 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/myth-reference-types-live-on-heap-value-types-lives-on-stack</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I was Reading the book C# in Depth by Jon Skeet wherein there was a section about Myths developers have about c#. One of the myth was about where the reference types and value types are stored in memory. I used to believe that reference types are stored in Heap and Value types are stored in stack. But the truth is as Below</p>

<p>I am directly copy pasting the excerpt from the book :)</p>

<p>” The first part is correct—an instance of a reference type is always created on the heap. It’s the second part that causes problems. As I’ve already noted, a variable’s value lives wherever it’s declared—so if you have a class with an instance variable of type int, that variable’s value for any given object will always be where the rest of the data for the object is—on the heap. Only local variables (variables declared within methods) and method parameters live on the stack. In C# 2 and later, even some local variables don’t really live on the stack”</p>]]></content:encoded><description>I was Reading the book C# in Depth by Jon Skeet wherein there was a section about Myths developers have about c#. One of the myth was about where the reference types and value types are stored in memory. I used to believe that reference types are stored in Heap and Value types are stored in stack. But the truth is as Below</description></item><item><title>Javascript Global Variable Is Actually A Property Of Window Object</title><link>https://taherchhabra.github.io/blog/Javascript-global-variable-is-actually-a-property-of-window-object</link><category>Design Pattern</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Thu, 15 Sep 2011 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/Javascript-global-variable-is-actually-a-property-of-window-object</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I was reading about JQuery and came to know something about Javascript global variables.
A Javascript glabal variable is declared as follows</p>

<p>var myGlobalVar = 5;
function myFunction()
   alert(myGlobalVar); // 5
}</p>

<p>The above code will give you result 5
Now use the code given below</p>

<p>var myGlobalVar = 5;
function myFunction()
   alert(window.myGlobalVar); // 5
}</p>

<p>Voila !!
The Global variable became the property of the window object.</p>]]></content:encoded><description>I was reading about JQuery and came to know something about Javascript global variables. A Javascript glabal variable is declared as follows</description></item><item><title>Specification Pattern</title><link>https://taherchhabra.github.io/blog/specification-pattern</link><category>Design Pattern</category><author>noemail@noemail.org (Taher Chhabra)</author><pubDate>Tue, 23 Aug 2011 12:23:33 GMT</pubDate><guid isPermaLink="false">https://taherchhabra.github.io/blog/specification-pattern</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Suppose there is a method as shown below</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public List GetExpensiveProducts()
{
    List products = GetAllProducts();
    List expensiveProducts = new List();
    foreach (product p in products)
    {
        if(product.price &gt; 50)
        {
             expensiveProducts.add(p)
        }
    }
    return expensiveProducts;
}
</code></pre></div></div>

<p>It is a method which returns all expensive products and there are other 10 methods like</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GetExpensiveProductsInStock()
GetExpensiveProductsOutOfStock()
GetExpensiveProductInACategory() etc etc etc ..
</code></pre></div></div>

<p>now suddenly your business analyst says that “we need to change the definition of expensive products, now products having price higher than 100 are expensive products”</p>

<p>So you’ll need to change the code at 10 different places ..isnt it?</p>

<p>The Specification pattern comes to the rescue !!</p>

<p>Now you can write the above method like this</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public List GetExpensiveProducts()
{
    List products = GetAllProducts();
    List expensiveProducts = new List();
    ExpensiveProductSpecification spec = new ExpensiveProductSpecification ()
    foreach (product p in products)
    {
         if(spec.IsSatisfiedBy(p))
         {
               expensiveProducts.add(p)
         }
     }
     return expensiveProducts;
}
</code></pre></div></div>

<p>The abstract base class of the pattern is as follows</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public abstract class Specification
{
     public abstract bool IsSatisfiedBy(T obj);
}
</code></pre></div></div>

<p>to make a concrete specification, we just need to inherit from the above base class</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public class ProductPriceGreaterThanSpecification : Specification
{
     public override bool IsSatisfiedBy(Product product)
     {
          return product.Price &gt; 50
     }
}
</code></pre></div></div>

<p>We can also create composite specifications, For that we’ll need to create a generic Class named CompositeSpecification by deriving the base class as shown below</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public abstract class CompositeSpecification : Specification
{
       protected readonly Specification _leftSide;
       protected readonly Specification _rightSide;

       public CompositeSpecification(Specification leftSide, Specification rightSide)
       {
             _leftSide = leftSide;
             _rightSide = rightSide;
        }
}
</code></pre></div></div>

<p>now lets create concrete implementations of the CompositeSpecification</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public class AndSpecification : CompositeSpecification
{

        public AndSpecification(Specification leftSide, Specification rightSide): base(leftSide, rightSide)
        {

        }

        public override bool IsSatisfiedBy(T obj)
        {
            return _leftSide.IsSatisfiedBy(obj) &amp;&amp; _rightSide.IsSatisfiedBy(obj);
        }
}





public class OrSpecification : CompositeSpecification
{

         public OrSpecification(Specification leftSide, Specification rightSide): base(leftSide, rightSide)
         {

         }

         public override bool IsSatisfiedBy(T obj)
         {
              return _leftSide.IsSatisfiedBy(obj) || _rightSide.IsSatisfiedBy(obj);
         }

}





public class NotSpecification : CompositeSpecification
{

     public NotSpecification(Specification leftSide, Specification rightSide): base(leftSide, rightSide)
     {

     }

     public override bool IsSatisfiedBy(T obj)
     {
          return _leftSide.IsSatisfiedBy(obj) &amp;&amp; !_rightSide.IsSatisfiedBy(obj);
     }
}   
</code></pre></div></div>

<p>and some methods in our base class as follows</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public abstract class Specification
{
       public abstract bool IsSatisfiedBy(T obj);
       public AndSpecification And(Specification specification)
       {
            return new AndSpecification(this, specification);
       }

       public OrSpecification Or(Specification specification)
       {
              return new OrSpecification(this, specification);
       }

       public NotSpecification Not(Specification specification)
       {
            return new NotSpecification(this, specification);
       }
}
</code></pre></div></div>

<p>now we are ready to use some composite specifications as shown below</p>

<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public List GetExpensiveProductsInStock()
{

      List products = GetAllProducts();
      List expensiveProducts = new List();
      foreach (product p in products)
      {

          if(new ProductInStockSpecification().And(new ProductPriceGreaterThanSpecification()).IsSatisfiedBy(p);)
          {
               expensiveProducts.add(p)
          }
      }
      return expensiveProducts;
}
</code></pre></div></div>]]></content:encoded><description>Suppose there is a method as shown below</description></item></channel></rss>