查看: 1890|回复: 0

[教程] 【一网打尽】Raspberry Pi Week 7 – Day 5 (Beginning Object Orientated ...

[复制链接]
  • TA的每日心情
    开心
    2016-8-4 10:56
  • 签到天数: 242 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2015-3-29 16:03:29 | 显示全部楼层 |阅读模式
    分享到:
    Raspberry Pi Week 7 – Day 5 (Beginning Object Orientated Programming (OOP))

    C++ is very similar to C in terms of syntax and design. It was developed by a Danish computer scientist named Bjarne Stroustrup to overcome some of the limitations of the C programming language. One of the main objectives of C++ was to add object orientation to the C language. Object Object-oriented programming or OOP is a design philosophy that uses the concept of objects. Before this programming was historically procedural meaning it would take read the program at the top of the code and continue through each line. The input, process it and output the data. Using objects allows the programmer to build, combine and re-use objects.

    An example of an object would be a Dog. A dog has characteristics that determine that it is a dog such as 4 legs, they can bark, they eat and they can walk. A cat can also do most of these things except bark. The cat and the dog are animals and therefore share common traits of animals. An animal object may be have created with common information such as 4 legs, eat and walk. The dog and the cat can use these characteristics with minimal programming because an animal already knows how to eat and walk. All you would need to do is add the programming that will enable the dog to bark and the cat to meow.

    Raspberry-pi-oop-programming-cat-300x225.png

    An object is basically a “thing”, a something that can perform actions and has state. State means something name describes the object such as a name, a colour, the breed or the size. Actions are what define the objects behaviour. A dog can eat a sandwich. A dog is an object and a sandwich is an object. Everything you look at is an object and can be described by its actions, also known as behaviours and its properties. An example of object behaviour could be to walk, roll, run, light up, produce sound or wag tail.

    In C++ you will use a class to define your objects. A class represent the type of object by creating a blue print of what the object can do. For example, think of a car production plant. After they have decided that they need a new car they will first design the car using a CAD program. When they have finalised the design they will produce many cars based on this blue print design. Think of a class as the CAD drawing from which every object is built from.

    programming-class.png


    A class in C++ looks like this.

    class Car {

    }

    Even cars are made up of other objects. Wheels, windows, seats, doors etc. are all objects. What this means is that the car object can be made up of other objects.

    programming-components-300x264.png

    Object-oriented programming is an in depth subject that we will dive into at a later stage but for now just keep in mind that C++ can use this method. OOP makes programming easier by breaking larger problems into smaller more manageable problems.  Remember that Object-oriented programming  represents the concept of objects that uses data fields and methods.  OOP is a fascinating area of computer science that we will explore again in depth later.


    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-27 12:13 , Processed in 0.107803 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.