Index
Overview
Steps
Problem Statement
Estimate
Crossroads
The Big Toolbox
Dig Into Component Toolbox
Delegation
Ideas Doc
Overview
This design challenge features
fractals...
Steps
Problem Statement
Code up a graphics class named "Drawer".
It's job will be to draw a variety of basic shapes such as ellipses and rectangles.
It will also draw
fractals
.
Estimate
We do a quick estimate.
We think that just the fractal generation will take about 1,000 lines of code.
Crossroads
We're at a crossroads.
Should we dive in and start coding, or take a detour and
look for code reuse
?
We decide to visit "look for code reuse".
The Big Toolbox
We pull out our #1 toolbox.
This toolbox contains reusable components.
Dig Into Component Toolbox
We look in the toolbox and find a component that looks like it could help -- a FractalGenerator class.
We grab it.
Delegation
We add the FractalGenerator as a component (ivar) on "Drawer".
When "Drawer" is asked to draw, it now simply
delegates
to it's component.
We replaced 1,000 lines of code with one message send by delegating to a component.
Ideas Doc
The "Ideas Doc" completed for this example is shown below or
downloadable here...
.
Coding Fundamentals
Chapter 201 - Ideas-Mode (Code Evaporation)
Example 1
Search Site
Home
Back To Top