Monday, June 25, 2012

Composite Pattern


Composite

A composite IS A group of objects in which some objects may contain others, so that some objects represent groups and others represent
individual items, or leaves.

You can bring these ideas together by defining a common type for groups and items and modeling groups as containing a collection of objects of this type.

The intent of the COMPOSITE pattern is to let clients treat individual objects and compositions of objects uniformly.




In software engineering, the composite pattern is a partitioning design pattern.
The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object

When to use
Composite can be used when clients should ignore the difference between compositions of objects and individual objects.
If programmers find that they are using multiple objects in the same way, and often have nearly identical code to handle each of them, then composite is a good choice; it is less complex in this situation to treat primitives and composites as homogeneous

http://en.wikipedia.org/wiki/Composite_pattern

facade pattern


The intent of the FACADE pattern is to provide an interface that makes a subsystem easy to use.
Facades often arise out of normal application development.
As you separate your code’s concerns into different classes, you may refactor (restructure) the system by extracting a class whose primary job is to provide simplified access to a subsystem.

http://members.comu.edu.tr/msahin/courses/ust_duzey_files/patterns/facade.pdf

adapter pattern

AN OBJECT IS A client if it needs to call your code.

For example, a rocket-simulation program might be designed to use rocket information that you supply, but such a simulation will have its own definition of how a rocket should behave. In such circumstances, you may find that an existing class performs the services that a client needs but has different method names. In this situation, you can apply the ADAPTER pattern.

The intent of ADAPTER is to provide the interface that a client expects while using the services of a class with a different interface.

The ADAPTER pattern lets you use an existing class to meet a client class’s needs.

When a client specifies its requirements in an interface, you can usually create a new class that implements the interface and subclasses an existing class.
This approach creates a class adapter that translates a client’s calls into calls to the existing class’s methods.




In computer programming, the adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface.

An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface.

The adapter translates calls to its interface into calls to the original interface, and the amount of code necessary to do this is typically small. The adapter is also responsible for transforming data into appropriate forms

http://en.wikipedia.org/wiki/Adapter_pattern

Categorization of Patterns

According to their intents:

  • Interfaces 

ADAPTER, FACADE, COMPOSITE, BRIDGE

  • Responsibility 

SINGLETON, OBSERVER, MEDIATOR, PROXY, CHAIN OF RESPONSIBILITY, FLYWEIGHT

  • Construction 

BUILDER, FACTORY METHOD, ABSTRACT FACTORY,PROTOTYPE, MEMENTO

  • Operations 

TEMPLATE METHOD, STATE, STRATEGY, COMMAND,INTERPRETER

  • Extensions 

DECORATOR, ITERATOR, VISITOR



     Types of design patterns according to their purposes:

  • – Creational: creating, initializing and configuring classes and objects
  • – Structural patterns: composition of classes and objects
  • – Behavioral patterns: dynamic interactions among classes and objects


  • Classification and list

  1. Creational patterns
  2. Structural patterns
  3. Behavioral patterns
  4. Concurrency patterns
http://en.wikipedia.org/wiki/Software_design_pattern



  • What are the categories design patterns divided into?
Ans. There are total three categories into which design patterns divided.
Creational Pattern:Creational patterns provide ways to instantiate single objects or group of related objects.
Structural Patterns:Structural patterns provide a way to define relationship between classes and objects.
Behavioral Patterns:Behavioral patterns define ways of communication between classes and objects.

Can you give name of patterns fall in each category?
Ans. Five patterns fall under creational pattern.
Abstract Factory
Factory
Factory Method
Prototype
Singleton
Seven patterns fall under structural pattern.
Adapter
Bridge
Composite
Decorator
Façade
Flyweight
Proxy
Eleven patterns fall under behavioral pattern.
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template Method
Visitor

What are object patterns?
Ans. Object patterns deals with object relationships that can be changed at runtime.
Object patterns mostly use object composition to establish relationships between objects.

What are class patterns?
Ans. Class patterns deals with class relationships that can be changed at compile time
class patterns tend to use inheritance to establish relationships.

Can you list down different class patterns and object patterns?
Ans.
Class Patterns
Adapter
Factory Method
Interpreter
Template Method
Object Patterns
Abstract Factory
Builder
Bridge
Chain of Responsibility
Command
Composition
Decorator
Façade
Flyweight
Iterator
Mediator
Memento
Observer
Prototype
Proxy
Singleton
State
Strategy
Visitor

http://jinaldesai.net/basic-design-patterns-interview-questions/

mock exam,test,quiz




  • SCJA Mini Mock Exam

http://www.ejavaguru.com/scjafreemockexam.php#a1


  • SCJA Sun Certified Java Associate Mock Exams

http://scja.de/

MVC over page centric



MVC is a design pattern
It contains two models:
MVC Model 1
MVC Model 2
Struts framework implements MVC Design Pattern.
Struts can implement Model 1 and Model 2

the important features of MVC1 architecture:
(1) HTML or JSP files are used to code the presentation.
JSP files use java beans to retrieve data if required.

(2)MVC1 architecture is page-centric design all the business and processing logic means any JSP page can either present in the JSP or may be called directly from the JSP page.

(3)Data access is usually done using Custom tag or through java bean call.
Therefore we can say that in MVC1 there is tight coupling between page and model


the important features of MVC2 architecture
(1)This architecture removes the page-centric property of MVC1 architecture by separating Presentation, Control logic and Application state

(2)In MVC2 architecture there is one Controller which receive all request for the application and is responsible for taking appropriate action in response to each request.

Second one is Model which is represented by JavaBeans, business object, and database.

Third one is View or is JSP page it takes the information provided by Controller and Module and presents it to user.


in MVC-I all the view,control elements are implemented using Servlets
in MVC-II the view is implemented using JSP,and the controller is implemented using Servlets,as JSP provides better user interface than Servlets

http://forums.sureshkumar.net/java-technologies/11167-struts-difference-between-mvc1-architecture-mvc2-architecture.html

PM course pages

lecture notes
http://efe.ege.edu.tr/~sengonca/Projeyonetimi.html

videos books
http://efe.ege.edu.tr/~sengonca/




PMP Study Process
http://pmstudent.com/pmp-exam-study-advice-that-works/pmp-study-process/

Earned Value Basics
http://pmstudent.com/evm-example-part-1-finding-pv-ev-and-ac/

Project Cost Management
http://www.preparepm.com/notes/cost.html


Project Cost Management
http://www.tutorialspoint.com/pmp-exams/project_cost_management.htm

bubble sort vs quick sort


  • bubble sort vs quick sort

http://www.youtube.com/watch?v=vxENKlcs2Tw
bubble sort compares every adjacent element(something next to it) and moves the biggest element forward

(if you are supposed to list numbers in descending order)
the same operation is run on the remaining part of the elements


  • Bubble sort

Bubble sort  is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order.
The algorithm gets its name from the way smaller elements "bubble" to the top of the list. 
Because it only uses comparisons to operate on elements, it is a comparison sort. 
Although the algorithm is simple, most other algorithms are more efficient for sorting large lists
Bubble sort has worst-case and average complexity both ?(n2), where n is the number of items being sorted

There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). 
Even other O(n2) sorting algorithms, such as insertion sort, tend to have better performance than bubble sort
Therefore, bubble sort is not a practical sorting algorithm when n is large.
Performance of bubble sort over an already-sorted list (best-case) is O(n).

 Large elements at the beginning of the list do not pose a problem, as they are quickly swapped. 
 Small elements towards the end, however, move to the beginning extremely slowly.
 This has led to these types of elements being named rabbits and turtles, respectively



 Pseudocode implementation

 procedure bubbleSort( A : list of sortable items )
   repeat     
     swapped = false
     for i = 1 to length(A) - 1 inclusive do:
       /* if this pair is out of order */
       if A[i-1] > A[i] then
         /* swap them and remember something changed */
         swap( A[i-1], A[i] )
         swapped = true
       end if
     end for
   until not swapped
end procedure

many modern algorithm textbooks avoid using the bubble sort algorithm in favor of insertion sort


http://en.wikipedia.org/wiki/Bubble_sort



  • Code snippets


Java

public void bubbleSort(int[] arr) {
      boolean swapped = true;
      int j = 0;
      int tmp;
      while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < arr.length - j; i++) {                                       
                  if (arr[i] > arr[i + 1]) {                          
                        tmp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = tmp;
                        swapped = true;
                  }
            }                
      }
}
C++

void bubbleSort(int arr[], int n) {
      bool swapped = true;
      int j = 0;
      int tmp;
      while (swapped) {
            swapped = false;
            j++;
            for (int i = 0; i < n - j; i++) {
                  if (arr[i] > arr[i + 1]) {
                        tmp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = tmp;
                        swapped = true;
                  }
            }
      }
}


http://www.algolist.net/Algorithms/Sorting/Bubble_sort