what is a framework?

A set of cooperative classes that makes up a reusable design for a specific class of software.

key points

Overview of Frameworks

Frameworks are more than just a set of components put together. Like components, Frameworks encapsulate data and functionality behind a set of stable interfaces. Developers don't need to dive into the low-level details of a Framework in order to use it.

A Framework is not a complete application, only part of one. In order to actually use it, the Framework must be extended by subclasses. An example is the JFrame window provided by Java Swing. To create a GUI window in a custom application classes must extend the JFrame class.

benefits of frameworks

Frameworks allow developers to incorporate systematic code reuse into their work. This in turn brings good design techniques into future applications that are reliable and well designed.

modularity

  • Frameworks encapsulate volatile implementation detail behind stable interfaces.
  • Localizes the impact of design and implementation changes.

reusability

  • Generic components are provided that can be reused in several parts of the application.

extensibility

  • Generic components of the framework can be extended to create new classes which in turn provide new functionality.

inversion of control

  • Allows the framework to control the flow of events while the application is running.

Types of Frameworks

White Box

  • Most early Frameworks were white box.
  • Came with source code, hence the name "white box."
  • Typically expanded by subclassing existing abstract classes. This required knowledge of the internal workings of the Framework.
  • Generally they are easier to customize.

Black Box

  • Called "black box" because the internal workings is not directly accessible.
  • Similar to components because they can only be accessed through their interfaces.
  • Generally they are more stable since all usage is anticipated through the interfaces.

Building with Frameworks

Framework developers can provide "hooks" and "hot spots" to areas that allow variability. These are usually accomplished through the use of interfaces and abstract classes. They provide a list of responsibilities that developers must implement when extending the Framework.

Classifying Frameworks

Here is a list of some common frameworks that are used:

    ApplicationFramework(s)
    DatabaseJRelational
    GraphicalJava Swing, MVC
    NetworkingJava RMI
    TestingJUnit
    OtherJava Collections

The Collections Framework

The Java Collections Framework is a unified architecture for representing and manipulating collections.

Create a new Collection using the Collections Framework

The Collections Framework provides several hooks that can be used for creating a new implementation of a Collection.

HookDescription
AbstractCollectionThis class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface. To implement this class the size() and iterator() methods need to be provided.
AbstractSetProvides skeletal implementation of a Set that conforms to the Set interface. To implement this class the size() and iterator() methods need to be provided.
AbstractListProvides a skeletal implementation of a List. To implement this class the programmer only needs to provide methods for get(), size(), and size() methods.
AbstractQueueProvides a skeletal implementation of a Queue. To implement this class the programmer needs to provide offer(E), poll(), peek(), size(), iterator(), and remove() methods.

MyArrayList.java

private static class MyArrayList<E> extends AbstractList<E>
{
    /**
     * The array that will represent this Collections class
     */

    private final E[] array;
   
    /**
     * Constructor for creating a new MyArrayList.
     * @param array an array of type E
     */

    
    MyArrayList(E[] array)
    {
        this.array = array;
    }

    /**
     * Get the element located at a particular index.
     * @param index the index the element is located at
     * @return the element located at position index
     */

    public E get(int index)
    {
        return this.array[index];
    }
   
    /**
     * Replaces the element at a particular index with another element.
     * @param index the index of the element to be replaced
     * @param element the element that will replace the existing index
     * @return the element that used to be at position index
     */

    public E set(int index, E element)
    {
        E oldValue = this.array[index];
        this.array[index] = element;
        return oldValue;
    }

    /**
     * Returns the size of MyArrayList.
     * @return the size of MyArrayList
     */

    public int size()
    {
        return this.array.length;
    }
}

Excercise

Now that you know a little bit about Frameworks, here's an exercise to complete.