ict.ken.be

 

Posts in Category: Patterns

semver 

Categories: Patterns

Semver explained in 3 words: v Breaking.Feature.BugFix

more: http://semver.org/

Glossary 

Categories: Patterns
  • Incoming Tests: methods that check the functionality of dependencies your project relies on.
  • Outgoing Tests: methods that check the end functionality of your product
  • Middleware: software that sits at the front of the back-end (eg. NodeJS, OWIN)
  • Middle-end: software that sits at the back of the front-end (eg. BreezeJS)
  • Spark: templated solution that can be used to speed up the startup of a project.
  • Spike: proof of concept for one specific project.



"Working Software" is software that users are actually using. Until it's in use it is truly useless.

Woody Zuill

Principles of OOD 

Categories: Patterns

http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

  • SRP - The Single Responsibility Principle : A class should have one, and only one, reason to change.
  • OCP - The Open Closed Principle : You should be able to extend a classes behavior, without modifying it.
  • LSP - The Liskov Substitution Principle : Derived classes must be substitutable for their base classes.
  • ISP - The Interface Segregation Principle : Make fine grained interfaces that are client specific.
  • DIP - The Dependency Inversion Principle : Depend on abstractions, not on concretions.

C# Singleton Pattern 

Categories: Patterns
// Singleton pattern -- .NET optimized

using System;
using System.Collections.Generic;
 
namespace DoFactory.GangOfFour.Singleton.NETOptimized
{
  /// 
  /// MainApp startup class for .NET optimized
  /// Singleton Design Pattern.
  /// 
  class MainApp
  {
    /// 
    /// Entry point into console application.
    /// 
    static void Main()
    {
      LoadBalancer b1 = LoadBalancer.GetLoadBalancer();
      LoadBalancer b2 = LoadBalancer.GetLoadBalancer();
      LoadBalancer b3 = LoadBalancer.GetLoadBalancer();
      LoadBalancer b4 = LoadBalancer.GetLoadBalancer();
 
      // Confirm these are the same instance
      if (b1 == b2 && b2 == b3 && b3 == b4)
      {
        Console.WriteLine("Same instance\n");
      }
 
      // Next, load balance 15 requests for a server
      LoadBalancer balancer = LoadBalancer.GetLoadBalancer();
      for (int i = 0; i < 15; i++)
      {
        string serverName = balancer.NextServer.Name;
        Console.WriteLine("Dispatch request to: " + serverName);
      }
 
      // Wait for user
      Console.ReadKey();
    }
  }
 
  /// 
  /// The 'Singleton' class
  /// 
  sealed class LoadBalancer
  {
    // Static members are 'eagerly initialized', that is,
    // immediately when class is loaded for the first time.
    // .NET guarantees thread safety for static initialization
    private static readonly LoadBalancer _instance =
      new LoadBalancer();
 
    // Type-safe generic list of servers
    private List _servers;
    private Random _random = new Random();
 
    // Note: constructor is 'private'
    private LoadBalancer()
    {
      // Load list of available servers
      _servers = new List
        {
         new Server{ Name = "ServerI", IP = "120.14.220.18" },
         new Server{ Name = "ServerII", IP = "120.14.220.19" },
         new Server{ Name = "ServerIII", IP = "120.14.220.20" },
         new Server{ Name = "ServerIV", IP = "120.14.220.21" },
         new Server{ Name = "ServerV", IP = "120.14.220.22" },
        };
    }
 
    public static LoadBalancer GetLoadBalancer()
    {
      return _instance;
    }
 
    // Simple, but effective load balancer
    public Server NextServer
    {
      get
      {
        int r = _random.Next(_servers.Count);
        return _servers[r];
      }
    }
  }
 
  /// 
  /// Represents a server machine
  /// 
  class Server
  {
    // Gets or sets server name
    public string Name { get; set; }
 
    // Gets or sets server IP address
    public string IP { get; set; }
  }
}

 

Output:
Same instance

ServerIV
ServerIV
ServerIII
ServerV
ServerII
ServerV
ServerII
ServerII
ServerI
ServerIV
ServerIV
ServerII
ServerI
ServerV
ServerIV
Page 1 of 2 1 2 > >>