Quick Index
Index

Overview


This chapter will build on the concepts learned in the previous chapter.

We'll be primarily learning about abstract data type (ADT).

We'll also cover concrete data type (CDT).

Idea


Think about the abstract data type (ADT) (i.e. "idea") of a Drawable. It is the "idea":


That's it -- end of story -- just an idea -- no real graphics work.

Reality


Now we've been asked for the logic on how to draw a Fractal. We need to do math and graphics research to come up with a solution so we can really draw a beautiful fractal.

Think about the CDT (i.e. "real type") Fractal:


We can say:


In General:


Hood Surface and Engine Quiz


These questions apply to the ADT and CDT (types) and the previously discussed "Drawable" type.

Which type is like a hood (surface) with no engine?

  • The ADT -- it is like a hood surface only
  • It is the idea (dream) for an drawable object
Which type is like a hood (surface) plus engine?

  • A CDT has a hood surface where it declares "draw"
  • It also has an engine "under the hood" where it actually carries out the logic to draw


ADT Example - Drawable


Defining


This is an example of how we would define the ADT "Drawable".

Description: the concept of a drawable is an object that knows how to draw itself. This is a "one-method ADT" (small ADTs are relatively common).

Example: in a graphics system we may have a circle, line, point, fractal, etc who all know how to "draw".

ADT Spec:
ADT Name: Drawable

draw(drawing);
	/*
	Draw self ("this" drawable object) onto the passed parameter "drawing". No return value.
	*/


Using


Draw objects
Here is a sample that simply iterates over a collection of drawables and sends the "draw" message to each.

The expected result would be a lovely drawing.
drawAllOn(drawables, drawing) {
	for (let nextDrawable in drawables) {
		nextDrawable.draw(this);
	}
}


Satisfying the ADT Spec


We say that an object type satisfies (meets) the ADT spec. This means that it fully supports all the methods specified on the ADT.

In the case of the "Drawable" ADT, this means, the object type would need to provide (handle) the "draw" method. When we move our project from design into coding, we'll call this "implementing" the ADT.

Objects that might satisfy this ADT would be a circle, line, fractal and countless more.

We would say:


ADT Example - Pair


Defining


This is an example of how we would define the ADT "Pair".

Description: the concept of a pair -- a pair (two) ordered elements. Both elements of the pair could be any object.

Example: We may have a pair where the first element is month number (e.g. 3) and the secnod is a month name (e.g. "March").

ADT Spec:
ADT Name: Pair

first();
	/*
	Return the first element in the pair (an object).
	*/

last();
	/*
	Return the last element in the pair (an object).
	*/


Using


Title Here
This is how we might use a Pair.
let pair = getPairExample()
let first = pair.first()
let last = pair.last()
//Send messages to first and last as desired


Satisfying the ADT Spec


We say that an object type satisfies (meets) the ADT spec. This means that it fully supports all the methods specified on the ADT.

In the case of the "Pair" ADT, this means, the object type would need to provide (handle) the two ADT methods above.

Objects that might satisfy this ADT could incude a key-value or a "range" with a start and stop.

A collection (of size two) could be a pair.

We would then say:


References




Navigation