Saturday, 20 August 2016

Amazon Webservices

What is cloud computing?
    Enables organization to obtain flexible, secure, and cost-effective IT infrastructure.
Just pay what you use. No upfront payment charged.

Infrastructure can have virtual servers, databases, storage, Messaging etc.

AWS platform has been divided into following categories:
    Compute and Network
        Amazon EC2- Supports most of OS in market-
        Amazon Route53
        Amazon VPC - Virtual private cloud
    Storage and Content Delivery
        Amazon S3(Simple Storage solutions)- Website hosting
        Amazon Glacier - to achieve the data
        Amazon CloudFront -
    Databases
        MYSQL
        MY sql server
        Oracle
    Application Services(Messaging and notifications)
        Amazon SES- Messaging
        Amazon SNS- Notification alerts
    Deployment and Management
        Amazon cloudwatch
        Amazon IAM(Identity and access management) -

Cloud Computing

  • What is Cloud
    •  Enables organization to obtain flexible, secure, and cost-effective IT infrastructure.
      Just pay what you use. No upfront payment charged. Infrastructure can have virtual servers, databases, storage, Messaging etc.
  • Service Models.
    • IAAS - Infrastructure as service - AWS, Azure
    • PAAS - Platform as service - AWS
    • SAAS - Software as service - GMAIL (Multi tenant environment) 
      • Best value for money
http://robertgreiner.com/uploads/images/2014/AzureServicesOverview.png
  • Essential Characteristics
    • On demand self service - Provision computing capabilities, such as server time and network usage, as needed automatically without manual intervention
    • Broad network access - Capabilities are available over network and accessed through standard mechanisms that promote use by heterogeneous thin or thick client platforms(eg: mobiles, tablets, laptops and workstations)
    • Resource Pooling -  The provider's computing resources are pooled to serve multiple consumers using a multi-tenant model, with different physical and virtual resources dynamically assigned and reassigned according to consumer demand. There is a sense of location independence in that the costomer generally has no control or knowledge over the exact location of the provided resources but may be able to specify location at a higher level of abstraction. Examples or resources include storage, processing, memory, and network bandwidth
    • Rapid elasticity: Capabilities can be elastically provisioned and released, in some cases automatically, to scale rapidly outward and inward commensurate with demand. To the consumer, the capabilities available for provisioning often appear to be unlimited and can be appropriated in any quantity at any time.
    • Measured service: Cloud systems automatically control and optimize resource use by leveraging a metering capability at some level of abstraction appropriate to the type of service(e.g., storage, processing, bandwidth, and active user accounts). Resource usage can be monitored, controlled, and reported, providing transparency for both the provider and consuer of the utilized service.
  • Deployment Models(Procurement model for cloud)
    • Private cloud: The cloud infrastructure is provisioned for exclusive use by a single organization comprising multiple consumers. It may be owned, managed, and operated by the organization, a thrird party, or some conbination of them, and it may exist on or off premises.
    • Community cloud: The cloud infrastructure is provisioned for exclusive use by a specific community of consumers from organizations that have shared concerns. It may be owned, managed, and operated by one or more of the organizations in the community, a thrid party, or some combination of them, and it may exist on or off premises.
    • Public cloud: The cloud infrastructure is provisioned for open use by the general public. It may be owned, managed, and operated by a business, academic, or government organization, or some combination of them. It exits on the premises of the cloud provider.
    • Hybrid cloud: The cloud infrastruture is a composition of two or more distinct cloud infrastrucres(private, community, or public) that remain unique entities, but are bound together by standardized or proprietary technology that enables data and application portability.

Saturday, 6 August 2016

Java Design Patterns

Design Pattern: Solution for known  design problems.
Creational Design Pattern
Singleton Design Pattern - One and ONLY copy of an Object

  • Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the java virtual machine.
  • To make an instance of an object globally available and guarantee that only one instance of the class is created.
  • Singleton provides a global, single instance.
  • Steps to create
    • Make the constructor as private(so that object can be created from the same class only)
    • Maintain a private static variable to hold the instance reference
    • Create a public static method to create instance if the static variable is NULL. Otherwise just return the instance from the static variable reference.
    • Make sure the method is thread safe
Advantage of Singleton Pattern over Static Class in Java: Main advantage of Singleton over static is that former is more object oriented than later. With Singleton, you can use Inheritance and Polymorphism to extend a base class, implement an interface and capable of providing different implementations.
  • If your requirements needs to maintain state than Singleton pattern is better choice than static class, because maintaining  state in later case is nightmare and leads to subtle bugs. 
  • Singleton classes can be lazy loaded if its an heavy object, but static class doesn't have such advantages and always eagerly loaded.
Factory Design Pattern
  • In factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface
  • In simple words, if we have a super class and sub-classes, based on data provided, we have to return the object of one of the sub-classes, we use a factory pattern. 
  • Factory design pattern is used when we have a super class with multiple sub-classes and based on input, we need to return one of the sub-class. This pattern take out the responsibility of instantiation of a class from client program to the factory class. We can apply Singleton pattern on Factory class or make the factory method static
  •  If object creation code is spread in whole application, and if you need to change the process of object creation then you need to go in each and every place and make necessary changes.
  • Lot of Scattered new keyword(Avoid it by introducing factory class)
  • Client is aware of all implementation types.(avoid it by interfaces)
  • It is to break link between client and concrete classes
  • low coupling
Abstract Design Pattern
  • Abstract factory pattern is a super factory. It is a factory which creates other factories. This factory is also called as factory of factories
  • Abstract Factory pattern is similar to Factory pattern and it’s factory of factories. In Factory design pattern, we have a single Factory class that returns the different sub-classes based on the input provided and factory class uses if-else or switch statement to achieve this.

    In Abstract Factory pattern, we get rid of if-else block and have a factory class for each sub-class and then an Abstract Factory class that will return the sub-class based on the input factory class. 
Builder Pattern

  • This pattern was introduced to solve some of the problems with Factory and Abstract Factory design patterns when the Object contains a lot of attributes. Builder pattern solves the issue with large number of optional parameters and inconsistent state by providing a way to build the object step-by-step and provide a method that will actually return the final Object. Check out Builder Pattern for example program and classes used in JDK.
    • This is used when Class constructor has too many arguments & user doesn't want to provide values at once
    • Builder class will have same set of parameters and returns object with NULL values. 
    • All setters will set the value and return the builder object
    •  

Prototype Pattern

  • Prototype pattern is used when the Object creation is a costly affair and requires a lot of time and resources and you have a similar object already existing. So this pattern provides a mechanism to copy the original object to a new object and then modify it according to our needs. This pattern uses java cloning to copy the object.

    Prototype design pattern mandates that the Object which you are copying should provide the copying feature. It should not be done by any other class. However whether to use shallow or deep copy of the Object properties depends on the requirements and its a design decision. Check out Prototype Pattern for sample program. 
Marker Interface Design Pattern
public interface DemoMarkerInterface{}
public class DemoClass implements DemoMarkerInterface{}
public class Driver {
    DemoClass democlass=new DemoClass();
    if (democlass instanceof DemoMarkerInterface)
        System.out.println("DemoClass is a DemoMarkerinterface");

}

Data Access Object Pattern
  • DAO pattern is used to separate low level data accessing API or operations from high level business services
  • DAO layer is responsible for Data Access from the persistence storage and manipulation of data in the persistence storate
  • Decouple the persistent storage implementation from the rest of your application
  • Intermediate layer between business and database layer. It just contains methods for CRUD operations. No business logic is present.
  • Main Use of DAO Layer
    • Used to perform the CRUD operations
DAO
  • Class that contains the basic CRUD operations for one entity class. It has the necessary code to get or retrieve things of the underlying persistent storage system
Repositories
  • In a higher level of abstraction.. as generally I have read is a kind of place where put code that handle operations over aggregate objects (objects that have child objects). 
DDD: Repository Implementation Patterns

https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-design