Friday, 30 August 2013

Iterator Design Pattern - Implementation


Click here to watch in Youtube : https://www.youtube.com/watch?v=uRiKSJAnmeA

Click the below Image to Enlarge
Iterator Design Pattern - Implementation

















IteratorPatternDemo.Java

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class IteratorPatternDemo
{

public static void main( String[] args )
{
ArrayList<String> listOfCountries = new ArrayList<String>();
listOfCountries.add("India");
listOfCountries.add("US");
listOfCountries.add("Japan");
listOfCountries.add("France");

Iterator<String> iterator = listOfCountries.iterator();
System.out.println("Iterator type for the Datastructure ArrayList : "+iterator.toString());
System.out.println();
while( iterator.hasNext() )
{
String countryName = iterator.next();
System.out.println("Country Name : " + countryName);
}
System.out.println();
Set<String> setOfCountries = new HashSet<String>();
setOfCountries.add("India");
setOfCountries.add("US");
setOfCountries.add("Japan");
setOfCountries.add("France");
Iterator<String> iterator1 = setOfCountries.iterator();
System.out.println("Iterator type for the Datastructure HashSet : "+iterator1.toString());
System.out.println();
while( iterator1.hasNext() )
{
String countryName = iterator1.next();
System.out.println("Country Name : " + countryName);
}

}

}

Output

Iterator type for the Datastructure ArrayList : java.util.AbstractList$Itr@12dacd1

Country Name : India
Country Name : US
Country Name : Japan
Country Name : France

Iterator type for the Datastructure HashSet : java.util.HashMap$KeyIterator@30c221

Country Name : France
Country Name : US
Country Name : Japan
Country Name : India

Iterator Design Pattern - Introduction


Click here to watch in Youtube : https://www.youtube.com/watch?v=Pganyj1dVVU

Click the below Image to Enlarge
Iterator Design Pattern - Introduction
























See also:

  • Iterator Design Pattern - Implementation
  • Iterator Design Pattern - KeyPoints
  • All Design Patterns Links
  • Intercepting Filter Design Pattern - Implementation


    Click here to watch in Youtube : https://www.youtube.com/watch?v=sWtchigtgXk

    Click the below Image to Enlarge
    Intercepting Filter Design Pattern - Implementation






















    Filter.Java

    public interface Filter
    {
    public void processRequest(String request);
    }

    AuthenticationFilter.java

    public class AuthenticationFilter implements Filter
    {

    @Override
            public void processRequest( String request )
            {
    System.out.println("Authenticating the request by AuthenticationFilter : " + request);
           
            }

    }

    LoggingFilter.java

    public class LoggingFilter implements Filter
    {
    @Override
            public void processRequest( String request )
            {
    System.out.println("Request Tracking is done by LoggingFilter : " + request);        
            }
    }

    Target.java

    public class Target
    {
    public void processRequest( String request )
    {
    System.out.println("Process the Request by Target Class: " + request);
    }
    }

    FilterChain.java

    import java.util.ArrayList;
    import java.util.List;

    public class FilterChain
    {
    private List<Filter> filters = new ArrayList<Filter>();
    private Target       target;

    public void addFilter( Filter filter )
    {
    filters.add(filter);
    }

    public void execute( String request )
    {
    for( Filter filter : filters )
    {
    filter.processRequest(request);
    }
    target.processRequest(request);
    }

    public void setTarget( Target target )
    {
    this.target = target;
    }
    }

    FilterManager.java

    public class FilterManager
    {
    FilterChain filterChain;

    public FilterManager( Target target )
    {
    filterChain = new FilterChain();
    filterChain.setTarget(target);
    }

    public void setFilter( Filter filter )
    {
    filterChain.addFilter(filter);
    }

    public void filterRequest( String request )
    {
    filterChain.execute(request);
    }
    }

    Client.java

    public class Client
    {
    FilterManager filterManager;

    public void setFilterManager( FilterManager filterManager )
    {
    this.filterManager = filterManager;
    }

    public void sendRequest( String request )
    {
    filterManager.filterRequest(request);
    }

    public static void main( String[] args )
    {
    FilterManager filterManager = new FilterManager(new Target());
    filterManager.setFilter(new AuthenticationFilter());
    filterManager.setFilter(new LoggingFilter());
    Client client = new Client();
    client.setFilterManager(filterManager);
    client.sendRequest("HOME");

    }

    }

    Output

    Authenticating the request by AuthenticationFilter : HOME
    Request Tracking is done by LoggingFilter : HOME


    Intercepting Filter Design Pattern - Class and Sequence Diagram


    Click here to watch in Youtube : https://www.youtube.com/watch?v=5MppAW_lGnQ

    Click the below Image to Enlarge
    Intercepting Filter Design Pattern - Class and Sequence Diagram

    Intercepting Filter Design Pattern - Introduction

    Front Controller Design Pattern - Implementation


    Click here to watch in Youtube : https://www.youtube.com/watch?v=NWNNsbMsrq4

    Click the below Image to Enlarge
    Front Controller Design Pattern - Implementation - Class Diagram























    UserView.java

    public class UserView
    {
    public void show()
    {
    System.out.println("Displaying User Page");
    }
    }


    SalaryView.java

    public class SalaryView
    {
    public void show()
    {
    System.out.println("Displaying Salary Page");
    }
    }


    AccountView.java

    public class AccountView
    {
    public void show()
    {
    System.out.println("Displaying Account Page");
    }
    }

    Dispatcher.java

    public class Dispatcher
    {
    private SalaryView  salaryView;
    private UserView    userView;
    private AccountView accountView;

    public Dispatcher()
    {
    salaryView = new SalaryView();
    userView = new UserView();
    accountView = new AccountView();
    }

    public void dispatch( String request )
    {
    if( request.equalsIgnoreCase("USER") )
    {
    userView.show();
    }
    else if( request.equalsIgnoreCase("ACCOUNT") )
    {
    accountView.show();
    }
    else
    {
    salaryView.show();
    }
    }
    }


    FrontController.java

    public class FrontController
    {
    private Dispatcher dispatcher;

    public FrontController()
    {
    dispatcher = new Dispatcher();
    }

    private boolean isAuthenticUser()
    {
    //here you have to write Authentication logic
    System.out.println("User is authenticated successfully.");
    return true;
    }

    private void trackRequest( String request )
    {
    System.out.println("Page requested: " + request);
    }

    public void dispatchRequest( String request )
    {
    // log each request
    trackRequest(request);
    // authenticate the user
    if( isAuthenticUser() )
    {
    dispatcher.dispatch(request);
    }
    }
    }

    FrontControllerPatternDemo.java

    public class FrontControllerPatternDemo
    {
    public static void main( String[] args )
    {
    FrontController frontController = new FrontController();
    frontController.dispatchRequest("USER");
    System.out.println();
    frontController.dispatchRequest("ACCOUNT");
    System.out.println();
    frontController.dispatchRequest("SALARY");
    }
    }

    Output

    Page requested: USER
    User is authenticated successfully.
    Displaying User Page

    Page requested: ACCOUNT
    User is authenticated successfully.
    Displaying Account Page

    Page requested: SALARY
    User is authenticated successfully.
    Displaying Salary Page


    See also:

  • Front Controller Design Pattern - Introduction
  • Front Controller Design Pattern - Class and Sequence Diagram
  • Front Controller Design Pattern - Key Points
  • All Design Patterns Links



  • Front Controller Design Pattern - Class and Sequence Diagram


    Click here to watch in Youtube : https://www.youtube.com/watch?v=HIluT1r6Kek

    Click the below Image to Enlarge
    Front Controller Design Pattern - Class and Sequence Diagram
























    Front Controller Design Pattern - Introduction

    Saturday, 24 August 2013

    Session State Design pattern


    Click here to watch in Youtube : https://www.youtube.com/watch?v=js-OlYuXRi4

    Click the below Image to Enlarge
    Session State  Design pattern















    See also:

  • All Design Patterns Links
  • Base Design Pattern


    Click here to watch in Youtube : https://www.youtube.com/watch?v=73iG2MSAY30

    Click the below Image to Enlarge
    Base Design Pattern














    See also:

  • All Design Patterns Links
  • Offline Concurrency Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=9UBuUDL76fI

    Click the below Image to Enlarge
    Offline Concurrency Patterns














    See also:

  • All Design Patterns Links
  • Distribution Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=cDgB46gx9V4

    Click the below Image to Enlarge
    Distribution Patterns














    See also:

  • All Design Patterns Links
  • Object-Relational Metadata Mapping Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=T7Dqys234X8

    Click the below Image to Enlarge
    Object-Relational Metadata Mapping Patterns















    See also:

  • All Design Patterns Links
  • Object-Relational Structural Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=icwcqXz7t3o

    Click the below Image to Enlarge
    Object-Relational Structural  Patterns














    See also:

  • All Design Patterns Links
  • Object-Relational Behavioral Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=7XOkyPNg4IU

    Click the below Image to Enlarge
    Object-Relational Behavioral Patterns














    See also:

  • All Design Patterns Links
  • Data Source Architectural Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=nUS7GdFcss4

    Click the below Image to Enlarge
    Data Source Architectural  Patterns















    See also:

  • All Design Patterns Links
  • Domain Logic Patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=R4vJK2zvUHc

    Click the below Image to Enlarge
    Domain Logic Patterns














    See also:

  • All Design Patterns Links
  • Behavioral design patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=kiTDR0YoIqA

    Click the below Image to Enlarge
    Behavioral design patterns

















    See also:

  • All Design Patterns Links
  • Structural design patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=CJN3D4BfKCk

    Click the below Image to Enlarge
    Structural design patterns

















    See also:

  • All Design Patterns Links
  • Creational Design patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=bTQ3owJOMFM

    Click the below Image to Enlarge
    Creational Design patterns

    Design patterns - catalog


    Click here to watch in Youtube : https://www.youtube.com/watch?v=JjwazgrE2LY

    Click the below Image to Enlarge
    Design patterns - catalog

















    See also:

  • All Design Patterns Links
  • Design patterns


    Click here to watch in Youtube : https://www.youtube.com/watch?v=EYOKqb2Mf7k

    Click the below Image to Enlarge
    Design patterns





    See also:

  • All Design Patterns Links
  • Messaging Design Pattern(MDP) - Implementation of Webservice


    Click here to watch in Youtube : https://www.youtube.com/watch?v=UdpAI8VBKYs

    Click the below Image to Enlarge
    Messaging Design Pattern(MDP) - Implementation of Webservice














    See also:

  • All Design Patterns Links
  • Messaging Design Pattern(MDP)-Implementation of Adapter


    Click here to watch in Youtube : https://www.youtube.com/watch?v=JF4Ul_Mb6xs

    Click the below Image to Enlarge
    Messaging Design Pattern(MDP)-Implementation of Adapter














    See also:

  • All Design Patterns Links
  • Messaging Design Pattern(MDP) - Implementation of Proxy


    Click here to watch in Youtube : https://www.youtube.com/watch?v=PYM_wxy5Tfo

    Click the below Image to Enlarge
    Messaging Design Pattern(MDP) - Implementation of Proxy














    See also:

  • All Design Patterns Links