Skip to main content

Posts

Showing posts from 2013

The GoF Hot Spots - Bridge vs Strategy

As part of my "GoF Design Patterns - The Hot Spots" posts series, this post is focused on two Design Patterns: Bridge and Strategy.

Although these two DPs are completely different, when googling them we encounter several common misconceptions that may make us think that Bridge and Strategy are similar or even same patterns.

I am not sure why but one of the popular misconceptions is that these two DPs shares the same UML diagram.

We will dig into the original GoF Design Patterns (aka: DP) description trying to figure out the real Hot Spots (aka: specific particular parts that differentiating them from each other) of these two DPs and the relationship between them.

In order to maximize the clarity of this article, I used two conventions:
Phrases inside [square brackets] are meant to help understanding GoF definitionsItalic sentences are GoF's book citations
StrategyGoF Definition"Define a family of algorithms [Classes that inherits from the same Abstract/Inte…

The GoF Hot Spots - Factory Method vs Abstract Factory

As part of my "GoF Design Patterns - The Hot Spots" posts series, this post is focused on two Creational Design Patterns: Factory Method and Abstract Factory.

We will dig into the original GoF Design Patterns (aka: DP) description trying to figure out the real Hot Spots (aka: specific particular parts that differentiating them from each other) of these two DPs and the relationship between them.

In order to maximize the clarity of this article, I used two conventions:
Phrases inside [square brackets] are meant to help understanding GoF definitionsItalic sentences are GoF's book citationsFactory Method GoF Definition:" [1] Define an interface for creating an object, [2] but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses."
GoF Description & Hot Pots: "Consider a framework for applications that can present [handle] multiple documents to the user. Two key abstractions in this framework are t…

GetHashCode Hands-On Session

The following is a hands-on post meant to demonstrate how GetHashCode() and Equals() methods are used by .NET Framework under the hood. For the sake of simplicity I will refer to the popular hashed-base Dictionary type, although any other hash based structure will follow a similar behavior, if not the same one. After understanding this post you should be able to spot potential problematic behaviors and resolve them, prevent creation of unreachable items in dictionaries and improve CRUD actions performance on hash based structures. The TheoryGetHashCode() is used to create a unique integer identifier for objects/structs. The hashcode can be used for two purposes: Programmatically, by developers, to distinguish objects/structs form each other (NOTE: Not recommended when the default .NET implementation is used, as it's not guaranteed to preserve the same hash between .NET versions and platforms)Internally, by .NET Framework, when using the object/struct as a key in a hashed based l…

GoF Design Patterns - The Hot Spots

Intro Now days, any programmer working with a language which conforms to the OOP paradigm, understands the power of Design Patterns (DP). A variety of great books are available for plain English interpretations for the various 23 GoF design patterns and the differences between them. Yet, there are still many controversies regarding how certain patterns differ and how they are related. Design Patterns, at first glance, sometimes appear very similar, not to say identical. When searching answers in forums, articles and blogs, I have encountered in a wide range of responses, starting from "It's the same DP and the only difference is the intend of the developer" and reaching "the questioned DPs are completely different and I can't even understand your question". If you sense that the truth lays somewhere in the between those responses, this new series of posts might interest you. This post is a first in a new series of posts, in which I will try to highlight …

SSL Distilled

A few days ago, my wife asked me: "why is it, sometimes when I access my web-mail account at work, I get a scary browser popup threatening and yelling at me that the site is dangerous and I should click 'OK'...?".
I am pretty sure this post will answer her question. SSL without Sweating Although SSL is very popular and well documented on many web articles, blogs, books & technical videos, when trying to really understand and assemble all the bits and bytes, you will probably find yourself breaking a sweat, because of the many misconceptions about this subjects. In this article I am going to give a brief top-to-bottom review of the must-know parts of SSL and try to re-explain the less familiar parts of this protocol. In order to make it easy for those of you that are familiar with SSL and only want to read the 'Hot' parts, I added an '*' as prefix to those points, so you guys can jump between them. …

Closures in C# vs JavaScript -
Same But Different

Closure in a Nutshell Closures are a Software phenomenon which exist in several languages, in which methods declared inside other methods (nested methods), capture variables declared inside the outer methods. This behavior makes captured variables available even after the outer method's scope has vanished.

The following pseudo-code demonstrates the simplest sample:
Main() //* Program starts from here { Closures(); } AgeCalculator() { int myAge = 30; return() => { //* Returns the correct answer although AgeCalculator method Scope should have ordinarily disappear return myAge++; }; } Closures() { Func ageCalculator = AgeCalculator(); //* At this point AgeCalculator scopeid cleared, but the captured values keeps to live Log(ageCalculator()); //* Result: 30 Log(ageCalculator()); //* Result: 31 } JavaScript and C# are two languages that support…

Understanding DateTime.ParseExact

When searching information about DateTime.ParseExact all documentations and blogs mention that the 'dateString' and the 'formatString' must be identical with the same date & time separators and format.
Although true, it's not the a precise description of what is going on under the hoods. Some times when needed this rule can be bypassed. I will explain later how. For now lets see the steel thread:
string dateString = "2012-01-01 13:30" string formatString = "yyyy-MM-dd HH:mm"; DateTime.ParseExact(dateString,formatString ,currentCultureFormatter) string dateString = "2012 01~01 13|30" string formatString = "yyyy MM~dd HH|mm"; DateTime.ParseExact(dateString,formatString ,currentCultureFormatter) string dateString = "2012-01|01 13~30" string formatString = "yyyy-MM|dd HH~mm"; DateTime.ParseExact(dateString,formatString ,currentCultureFormatter) NO…