Monday, June 15, 2015

Dependencies and layering

In above figure , Client A depends on service B  but Service B does not depend on the Client A
·        Unless Client A truly makes use of the service B, The Client A  does not load assembly of the service B
·        Cyclic dependencies ( suppose Service B depends on the service B) is not allowed in Visual Studio
·        Types :
o   First dependencies(Both Client A and service B belong to same visual studio solution )
o   Framework dependencies(like System,System.core ,They always loads these dependencies)
o   Third party dependencies(these dependencies are developed by third-party developers e.g. Entity Framework)
·        The simplest way to organize dependencies that are external to your project and the .NET Framework is to create a
solution folder called Dependencies under the Visual Studio solution of a project and to add the .dll files to that folder

Code Smells: It is a way of saying that some code is potentially problematic and presence of “new” keyword is generally consider as code smells
 Issues with Code Smells if present :
  • Inability to enhance the implementations
  • Creates Chain of dependency
  • Lack of test-ability
Alternatives to object construction :
  • Coding to interfaces
  • Using dependency injection
The Entourage anti-pattern :
  • Keeping the interfaces and implementations in the same assembly.
  •  Entourage means ask for one assembly and it gives all it assemblies
The Stairway Pattern :
  • Keep the interfaces and implementations in the different assembly so that we can vary the     two independently, and clients only need to make a single reference—to the interface assembly.
  •  Interfaces should not have any external dependencies. As far as possible, this should always be adhered to
  •  Interfaces should not have methods or properties that expose any data objects or classes defined in third-party references
  •   It can depend on classes and data types from other projects in the solution and common .NET  Framework libraries
  •   A reference to infrastructural entities(Third party dependencies ) should be avoided.
  •   Third party library such as Log4Net, NHibernate, and MongoDB are  packaged using the  entourage anti-pattern.
  •   To work around the above issue, make use of a simple interface that hides the third-party dependency behind a first-party dependency and an adapter
Layers vs. tiers :
         The difference between layers and tiers is the difference between the logical organization and physical deployment of code. Logically, you could separate an application in three or four layers, but physically deploy it into one tier. The number of tiers is somewhat related to the number of machines that the application is deployed to. If you deploy to a single machine, you are deploying an application in one tier. If you deploy the application to two machines, split by at least two layers, you are deploying to two tiers.

Cross-cutting concerns :
  • Sometimes ,Component’s responsibilities(exception logging) does not fit into any of layers like MVC layers and are applicable to any layers
  • Aspect- oriented programming is application of cross-cutting concerns and in .NET ,we have POSTSHARP
Command/query separation (CQS) :

       1. CQS-compliant and non–CQS-compliant command methods















2 .CQS-compliant and non–CQS-compliant query methods.












Command/Query Responsibility Segregation :

No comments:

Post a Comment