Posts

Showing posts from March, 2014

GoF Design Patterns - Quick Overview

GoF Creational PatternsAbstract FactorySets of methods to make various objects.BuilderMake and return one object various ways.Factory MethodMethods to make and return components of one object various ways.PrototypeMake new objects by cloning the objects which you set as prototypes.SingletonA class distributes the only instance of itself.
GoF Structural PatternsAdapterA class extends another class, takes in an object, and makes the taken object behave like the extended class.BridgeAn abstraction and implementation are in different class hierarchies.CompositeAssemble groups of objects with the same signature.DecoratorOne class takes in another class, both of which extend the same abstract class, and adds functionality.FacadeOne class has a method that performs a complex process calling several other classes.FlyweightThe reusable and variable parts of a class are broken into two classes to save resources.ProxyOne class controls the creation of and access to objects in another class. GoF Be…

Ultimate guide to learning AngularJS in one day

Maven Overview

What is Maven? From the website, the answer to the question: Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing: BuildsDocumentationReportingDependenciesSCMsReleasesDistributionMaven is not just a build tool, and not just a replacement for Ant. Maven is an entirely different creature from Ant. Ant is simply a toolbox whereas Maven is about the application of patterns in order to achieve an infrastructure which displays the characteristics of: Coherence - Maven allows organizations to standardize on a set of best practices. Because Maven projects adhere to a standard model they are less opaque. The definition of this term from the American Heritage dictionary captures the meaning perfectly: "Marked by an orderly, logical, and aesthetically …

Binary Tree in Java

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

public class BinaryTree {
private TreeNode root;

/** Inner class tree node */
private class TreeNode {
Object element;
TreeNode left;
TreeNode right;

public TreeNode(Object o) {
element = o;
}

}

/** Create a default binary tree */
public BinaryTree() {
}

/** Create a binary tree from an array of objects */
public BinaryTree(Object[] objects) {
for (int i = 0; i < objects.length; i++) {
insert(objects[i]);
}
}

/** Search element o in this binary tree */
public boolean search(Object o) {
return search(o, root);
}

public boolean search(Object o, TreeNode root) {
if (root == null) {
return false;
}
if (root.element.equals(o)) {
return true;
} else {
return search(o, root.left) || search(o, root.right);
}
}

/** Return the number of nodes in this binary tree */
public int size() {
return size(root);
}

public int size(TreeNode root) {
if (root == null) {
return 0;
} else {
return 1 + size(root.left) + size(root.right);
}
}

/**