Selecting Abstraction for Written Response 2d

Lets say a student writes a drawFish(size, R, G, B) function which can draw fish of different sizes and colors and a drawAllFish() function which calls drawFish 8 times in different location on the screen so that 8 fish are drawn, which would be the better choice to draw a rectangle around and explain how it manages complexity?

The drawFish function manages complexity because it it can be reused to draw all kinds of fish without worrying about the implementation details. But the drawAllFish function manages complexity because it calls drawFish in different locations and isolates the code for drawing fish into a single area/function call.

Do you think either of these functions would be good abstractions or just the drawFish function?

Both are abstractions. For the argument on reducing complexity I think it’s easier to use drawFish. The use of parameters to draw fish of various size and colors rather than having separate functions for each size and color certainly reduces complexity of the code. Any time a student has a function with parameters, actually uses the parameters (as obvious as that seems, I’ve seen otherwise) and calls that function more than once with different parameters should use that as their abstraction.

1 Like