@jax16,
I walk up to you and say, "My yard is a rectangle that is 50 ft. by 100 ft. Can you tell me the area?"
Rectangle is an ADT. There is no C++ code. There is no Java code. There is not LISP code. There is not assembler code. I am having a conversation with you about my yard, and reference a rectangle.
The idea of a rectangle is well defined. It has 4 sides, each parallel with its opposite. It has 4 angles that are all 90 degrees. The area can be determined by multiplying the lengths of 2 adjacent sides.
A rectangle is an abstract data type in this conversation.
Now, you decide to write a program for me to calculate the areas of all parcels of land that are rectangular in shape. You decide to write a Rectangle class as you described above.
Now we have the conceptual idea of a rectangle that we were discussing. And we have code that you wrote. The code that you wrote captures all of the concepts from the idea of a rectangle from our discussion. Your Rectangle class is an
implementation of the abstract data type "rectangle" that we were discussing.
I decide to write a rectangle class also.
1 2 3 4 5 6 7 8 9 10 11 12
|
class Doug_Rectangle
{
public:
// no constructor
void setTheWidth(int w) { width = w; }
void setTheHeight(int h) { height = h; }
int area() { return width * height; }
private
int width = 0;
int height = 0;
};
| |
My class is different than yours, but it still follows the same ideas of what a rectangle is.
Note: the interface is slightly different, so if, to you, the concept of a rectangle includes the ability to set both values at the same time, this would be a different abstract data type.
But in my world, the method of setting the height and width is an implementation detail and not central to the meaning of "rectangle". I developed a rectangle class that differed from yours, but they are both implementations of the abstract data type named "rectangle".
The same could be said about rectangle classes written in any other programming language.