Page 221 - Computer_Science_F5
P. 221

Computer Science  Meaning of Object Oriented
           Programming
           Object-oriented
                                 programming
           (OOP) is a programming concept
           that revolves around the idea of
           “Car” and one object instantiated from READING ONLY
           “objects.”  These objects hold data
           as  fields  (also  called  attributes  or
           properties) and code as procedures
           (also called methods). OOP enables
           developers to build programs in a
           modular  way and create  code that
           can be reused.                                 Figure 4.1: A car as an object


           In  OOP, objects  are  created  from   Another example can be represented by a class
           classes, which act as templates for    “Plant” with objects like Apple and Orange.
           creating  objects.  Classes specify    Apple has attributes like Name(Apple), Color
           the characteristics  and actions that   (Red), Taste (Sweet), and Weight (150g).
           objects of that class will possess.    It also has a method like Ripen(), rote(),
                                                  isSweet().
          FOR ONLINE
           Figure 4.1 represent a class named
                                                  The structures can be further explained as
           this class: Toyota. The object Toyota    follows:
           has specific attributes and methods.    (i)  Classes: Classes are user-defined data
           Attributes are characteristics or            types that act as blueprints for creating
           properties of an object, while methods       individual objects. They define the
           are actions or behaviors that the object     attributes and methods that objects
           can perform. For instance, Toyota            of that class will have.
           has attributes such as Make (Toyota),
           Model (Carina), Color (Silver),         (ii)  Objects: Objects are instances of a
           Year (2021), and Mileage (31500              class. They represent specific entities
           km), and it can perform methods              with  their  own  unique  data  and
           like StartEngine(), Accelerate(), and        behaviourr. Objects can correspond to
           Brake(). This summary provides a             real-world objects or abstract entities.
           clear overview of the attributes and    (iii)  Methods: Methods are functions
           methods associated with each object          defined inside a class that describe the
           within the “Car” class. The structure        behaviors of an object. They are used to
           of Object Oriented Programming can           perform specific actions or operations
           be explained using a car example, as         on objects. Methods can be reused and
           in Figure 4.1.                               encapsulated within objects.


                                                 212
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   212                                                     23/07/2024   12:33
   216   217   218   219   220   221   222   223   224   225   226