官术网_书友最值得收藏!

Generating blueprints for objects

Imagine that you want to draw and calculate the areas of four different rectangles. You will end up with four rectangles drawn, with their different widths, heights, and calculated areas. It would be great to have a blueprint to simplify the process of drawing each rectangle with their different widths and heights.

In object-oriented programming, a class is a blueprint or a template definition from which the objects are created. Classes are models that define the state and behavior of an object. After defining a class that defines the state and behavior of a rectangle, we can use it to generate objects that represent the state and behavior of each real-world rectangle.

Tip

Objects are also known as instances. For example, we can say each rectangle object is an instance of the rectangle class.

The following image shows four rectangle instances drawn, with their widths and heights specified: Rectangle #1, Rectangle #2, Rectangle #3, and Rectangle #4. We can use a rectangle class as a blueprint to generate the four different rectangle instances. It is very important to understand the difference between a class and the objects or instances generated through its usage. Object-oriented programming allows us to discover the blueprint we used to generate a specific object. Thus, we are able to infer that each object is an instance of the rectangle class.

We recognized four completely different real-world objects from the application's requirements. We need classes to create the objects, and therefore, we require the following four classes:

  • Square
  • Rectangle
  • Circle
  • Ellipse
主站蜘蛛池模板: 岳西县| 阳朔县| 彭水| 锡林浩特市| 关岭| 永顺县| 韶山市| 团风县| 宁津县| 桐乡市| 大竹县| 云浮市| 老河口市| 辰溪县| 镇雄县| 石屏县| 威远县| 绥滨县| 清涧县| 赤城县| 漳浦县| 高陵县| 彰武县| 通山县| 射洪县| 左云县| 湛江市| 阿瓦提县| 临海市| 清徐县| 女性| 乌兰浩特市| 商河县| 岐山县| 延寿县| 三明市| 阿巴嘎旗| 阜新市| 游戏| 苏州市| 嘉兴市|