Page 222 - Computer_Science_F5
P. 222

(iv)  Attributes: Attributes, also known      Exercise 4.1
                    as fields or properties, are defined
                    in the class template and represent   1.  What criteria must a programming
                    an object’s state. They store data      language meet in order to be
                    associated with objects.                classified as an Object-Oriented       Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
                                                            Programming language?
              The organisation of an object-oriented     2.  How are classes different from
              program through these structures              objects? Illustrate with your own
              promotes code reusability, scalability,       suitable examples.
              and efficiency.
                                                         3.  How would you explain the concept
              Code  reusability:    Is  the  practice  of   of a class to someone who has
              utilising existing code for new purposes      never encountered object-oriented
              without rewriting it. For example, in         programming before? Can you
              Object-Oriented Programming, specific         think of an everyday example that
              vehicle types like Cars,  Trucks, and         resembles a class in programming?
              Motorcycle  are  created  by  inheriting   4.  Why is it important to understand
              common functionalities from a superclass      the relationship between classes
              like Vehicle.                                 and objects in Object-Oriented
                                                            Programming? How does this
              Scalability: Is the system’s ability          relationship contribute to the
              to  handle  increased  workload  or           organisation and efficiency of
              expand  without  structural  changes.         code?
              For instance, in a banking application,
              adding new account types like checking   Key principles of Object-Oriented
              accounts without altering existing code
              demonstrates scalability.                Programming


              Efficiency: Refers to the optimal utilization   Encapsulation
              of system resources. For example,        To understand well the meaning of
              efficiently  storing  student  records  in   encapsulation, visualise how you are
              memory using data structures like arrays   going to build a house as shown in Figure
              and implementing fast sorting algorithms   4.2 for your household dog. In OOP this
              for large datasets showcases efficiency.  house represents a class.  This house
                                                       may have a bedroom for a dog to sleep
              OOP also facilitates  collaborative      in as well as a playroom. These rooms
              development  by dividing  projects  into   are examples of an attribute of the dog’s
              groups. OOP provides benefits such as    house. In this house a dog can have a door
              abstraction, inheritance, polymorphism,   for entering and for leaving outside the
              and encapsulation.                       pet dog house. This dog door represents

                                                    213
               Student’s Book  Form Five



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