Quick Index
Overview


We first develop the core of the object type (class) QueryArray.

In the next sections, we'll decorate the class with services (instance methods).

Object Design


The first thing we want to do is an initial object design (which can be changed and improved later).

Our design is simple: A query array has one instance variable (ivar) "elements" (a fixed array).

Our QueryArray will be a wrapper (decorator) of a fixed array:

QueryArray
	elements (an ivar that is a fixed array)



Code


Core Code
Here is the core of the QueryArray class.

  • Class name
  • Public constructor
  • Instance variable (elements )
  • Common toString method
class QueryArray {

	//---------------------------------
	//Instance Variables

	//elements --an ivar that is a fixed array

	//---------------------------------
	//Constructors

	static from(elements) {
		return new this(elements);
	}

	constructor(elements) {
		this.elements = elements;
	}

	//---------------------------------
	//Core

	toString() {
		return this.elements.toString();
	}

}

//Test It
let array = [10, 20, 30, 40];
let qarray = new QueryArray(array);
println(qarray.toString());