Package Managers

We have several package managers. Each of these package managers are designed with specific needs in mind and they each handle specific tasks better than the others.  Because of their different strengths, it is common to use all three of them within the same .Net web application.

NuGet

What is it?   .Net developers are likely to be very familiar with this.  It is a package manager that mainly deals with .NET assemblies.

What it is good for?  It is nicely integrated within Visual Studio and great for loading .Net assemblies and libraries such as Entity Framework and ASP.NET Identity.

NPM (Node Package Manager)

What is it?  Designed specifically for node modules, but is also ideal for loading packages that are used during development time. Unlike Bower, NPM supports nested dependency trees. Meaning, NPM may actually load multiple versions of a component on your machine.

What it is good for?  Great for managing developer tools like Yeoman, Grunt, Gulp, and testing tools. Its nested dependency tree makes it great for avoiding dependency conflicts.

Bower

What is it?   Bower is optimized for front-end components. Bower uses a flat dependency tree, requiring only one version for each package, reducing page load to a minimum. So where NPM aims for stability, bower aims for a smaller/faster footprint.

What it is good for?  Created specifically for managing front-end components like javascript and css files.

Observer Pattern C#

Observer

When do we go for event driven programming in our application? Why Action driven programming.  — When a state change in object(Data is altered, then certain algorithm should be executed) should execute certain piece of logics, then we should go for event driven programming. SendSMS is the algorithm to be executed when balance is credited/debited.

Data : Account Balance (which undergo change because of publisher)

Publisher : Update Method : who will raise the signal

Signal : Event/Listener

Observer : MessageCreator.SendSms

One to many : One publisher raises the signal to many Observers.

Decorator Pattern C#

Problem : lets say we have Class A and Class B.

Class B source code is not available for change. & it has a method that is being called in class A. What if we need to add additional logic to method in B. What to be done?

we can have a derived class B1 from B & add our own logic in method after calling the base.Echo().

    class A

{

public B b = new B();

public void M1()

{

b.Echo();

}

}

class B1 : B

{

public void Echo()

{

base.Echo();

//New steps

}

}

/// <summary>

/// Source code cannot be touched to change

/// </summary>

class B

{

public void Echo()

{

//Line 1

//Line 2

}

}

 

But what if class B is final/Sealed???  we can achieve what achieve with inheritance using Has-a relationship.

Decorator

class A

{

public IB b = new B1();

public void M1()

{

b.Echo();

}

}

class B1 : IB

{

public void Echo()

{

new B().Echo();

//New steps

}

}

/// <summary>

/// Source code cannot be touched to change

/// </summary>

class B : IB

{

public void Echo()

{

//Line 1

//Line 2

}

}

public interface IB    {

void Echo();

}

Composite1

 

It is again a wrapper class, mostly like proxy implementing the same  interface of the actual service provider. But the only difference is that it has additional logic apart from calling the serviceProvider. where as proxy is an exact call to actual service provider.

A Decorator is a change management utility which comes in hand if we are working with classes that are final and you don;t have the source code or you are not the owner of the source code to change. so you can create a wrapper around the source code & add your own extra logics.

Facade Pattern C#

Facade

Problem/Scenario

Facade1

 

Solution

Facade2

Facade represents the client side logics in server side. It is not object oriented representation, instead it is a structural implementation. It has multi level representations of different logics, not single responsibility. Still it is usefull in a way, that any change in logic, we need to change the facade instead of client code. So change management is easy. SO any remote client dealing with multiple clients, its better to root it through facade instead of tight coupling.

Facade is all about accessing different objects. Facade doesn’t even expose anything, it does portion of your job unlike Builder. (builder is all about creating the different objects.)