Software

Factory Method

Factory creates objects. The clients who use the factory can focus on other behavior. So the object creation delegated to another object.

Factory Object

Benefits: if there are multiple clients that want to instantiate the same set of classes, then by using a Factory object, you have cut out redundant code and made software easier to modify. Means if need a change of object creation, then have to modify just a factory instead of every client and it’s calling coding to an interface, not an implementation.

Factory:

public class CarFactory(){
    public Car createCar(string carType) {
        Car car;
        
        if(carType.Equals("sport")){
            car = new SportCar();
        }
        else if(carType.Equals("city")){
            car = new CityCar();
        }        

        return car;
    }
}
Continue reading “Factory Method”
Software

Singleton

The singleton pattern refers to having only one object of a class. Again, enforces one and only one object of a Singleton class which globally accessible within a program.

Code example:

public sealed class Singleton
{
   private static volatile Singleton instance;
   private static object syncRoot = new Object();

   private Singleton() {}

   public static Singleton Instance
   {
      get 
      {
         if (instance == null) 
         {
            lock (syncRoot) 
            {
               if (instance == null) 
                  instance = new Singleton();
            }
         }

         return instance;
      }
   }
}
Singleton Class Diagram.png
Singleton class diagram.
Software

Model Checking

How to make sure the system that you’ve created is correct?

For example, you can run tests and see if the actual behavior matches what you expect. But there is another technique called model checking.

Model Checking is a systematic check of your systems state model in all its possible states, can help to find laws. Its done after code has been written and before deployment.

How to model check software? Model checkers generate a State Model from your code.

State Model is an abstract state machine that can be in one of various states. The model checker then checks that the state model conforms to certain behavioral properties.

There are 3 different phases to performing model checking:

  1. The Modeling phase – this is where you enter the model description and describe the desired properties.
  2. The Running phase – can see how your model conforms to the desired properties that has been wrote in the modeling phase.
  3. The Analysis phase – checks if all the desired properties are satisfied and if any are violated. Violations are called Counterexamples. Also you can analyze how you got this state using the information from the model checker with advice where to fix. And then run the phases again until eliminate the issues.
Software

Separation of Concerns

Separation of Concerns principle helps to create flexible, reusable and maintainable software systems. But it is an ongoing process throughout the design process.

Concern it is anything that matters in providing a solution to a problem. Some of the concerns in software may involve:

  • What information the implementation represents.
  • What it manipulates.
  • What gets presented at the end.

Example with SmartPhone, let’s say we have the next class:

Continue reading “Separation of Concerns”
Software

Coupling and Cohesion

Coupling and cohesion are metrics to evaluate design complexity.

These metrics helps to achieve a more manageable system.

Coupling

Coupling focuses on complexity between a module and other modules. If your module is highly reliant on other modules, then this module is tightly coupled to others (puzzle). If your module finds it easy to connect to other modules, this module is loosely coupled to others (Lego).

Coupling.png
Coupling

When evaluating the coupling of a module, you need to consider degree, ease and flexibility.

Continue reading “Coupling and Cohesion”
Software

UML Class Diagram of a car rental company

Car Rental Company UML class diagram.png

This example has the next 4 entities:

  1. Car Rental Company: company itself, which is the “whole“.
  2. Car: cars owned by the company.
  3. Rental: rental entity (like contract), which is the “whole” for Car and Renter entities.
  4. Renter: a person who rent car.

All of the connections are composition. The system has the next generalization connections:

  • Car Rental Company Car: the company can have 0 or many cars; a car can have only 1 company.
  • Car Rental Company – Rental: the company can have 0 or many rentals; a renal can have only 1 company.
  • Car Rental Company – Renter: the company can have 0 or many renters; a renter assigned only o 1 company.
  • Rental – Car: 1 rental can be assigned to 1 car and vise versa.
  • Rental – Renter: each rental can have only 1 renter but a renter can have 0 or many rental.

Software

Software Quality Attributes

The attributes in the article are technical capabilities that should be used in order to fulfill the non-functional requirements, so the most important and common quality attributes are:

  1. Scalability.
  2. Manageability.
  3. Modularity.
  4. Extensibility.
  5. Testability.

In reality there are much more quality attributes: wikipedia.

Intro illities.png

Scalability

Adding computing resources without any interruption.

Non-Scalable System, which obviously require a lot of efforts to fix it:

  1. Look for non-scalable code.
  2. Rewrite non-scalable code.
  3. Reinforce VM.

Scalable System:

  1. Add VM.
  2. Notify the Load Balancer.

There are 2 types of scalability: scale up (vertical) and scale out (horizontal).

ScaleUpScaleDown.png

The preferable option is Scale Out which has 2 main benefits:

Continue reading “Software Quality Attributes”