Abstract Factory DesignPattern-1

Abstract Factory Design Pattern

  • In software development, a factory is the location in the code at which objects are constructed. 
  • The intent in employing the pattern is to insulate the creation of objects from their usage. This allows for new derived types to be introduced with no change to the code that uses the base class.
  • The essence of the Abstract Factory method Pattern is to "Provide an interface for creating families of related or dependent objects without specifying their concrete classes".
  • For Example:
    • Address Factory has no of factories like:
      • US Address Factory which implements the Address Interface.
      • French Address Factory which implements the Address interface.
      • Can have many more country specific factories….
  • When we create the French Address using the method implemented in the French Address Factory class it returns the Object reference to the Abstract class of Address.
  • The Abstract Address class holds the abstract method named get Country() which is implemented separately by each implementing class

JSTL Example

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"



<%@ taglib prefix="c" uri="/x" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">



<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>




    <c:out value="From JSTL Core Tag"></c:out>


    <c:catch> What is here?? </c:catch>

    <c:set var="counter" value="1"></c:set>

    <c:forEach begin="1" end="5" step="1">

        <c:out value="${counter}"> </c:out>

        <c:set var="counter" value="${counter}}"> </c:set>




Steps for using JSTL

1. Download jstl.jar from


2. Download standard.jar from


3. Extract and add the tlds in WEB-INF/lib folder by copy paste.


4. Edit Web.xml    for all such tlds




    <taglib-uri> /x </taglib-uri>

    <taglib-location> /WEB-INF/lib/c.tld </taglib-location>




5. Now in the jsp file add


<%@ taglib prefix="c" uri="/x" %>


6. Start using tags


    e.g. <C:out value="output this"> </c:out>

JSON Sample




<h2>JSON Object Creation in JavaScript</h2>


Name: <span id="jname"></span><br />

Age: <span id="jage"></span><br />

Address: <span id="jstreet"></span><br />

Phone: <span id="jphone"></span><br />



<script type="text/javascript">

var JSONObject= {

"name":"John Johnson",

"street":"Oslo West 555",


"phone":"555 1234567"};









Abstract Keyword

  • Abstract Keyword used for method declaration which doesnt have any implementation.
  • Abstract classes have abstract methods not having method implementation in the abstract class but in subclass.
  • When a class doent need to get instiated then that class is used as an abstract class. But this class is available for others to get exextended and use functionality.
  • The best example is the shape class.
  • The shape class having the method called area in its declaration.
  • which is different for all shapes class like it is different for squre, triangle, circle. each class inherits the shape class contains the functionality of that class ut it has to implement all "abstract methods" of the Shape class.
  • Abstract class needs to be extended first to instanciatiate.
  • Implementation

abstract ClassName()



abstract returntype MethodName1(Arg);

//This method needs to be iimplemented if this class is inherited.


ret_type MethodName2();








  • Example:


abstract class Shape{

    abstract void draw();


class Rectangle extends Shape{

    void draw(){

            System.out.println("Drawing Rectangle");



class Traingle extends Shape{

    void draw(){

System.out.println("Drawing Traingle");



class AbstractDemo{

public static void main(String args[]){

Shape s1=new Rectangle();


s1=new Traingle();





Drawing Rectangle

Drawing Traingle

JQuery Example

JQuery Example:

<title>jQuery Hello World</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
 $("#flag").html("Hello World !! (display due to jQuery)");
<font color=red> 
Hello World !! (display due to HTML)
<font color=blue>
<div id="flag">