Page 231 - Computer_Science_F5
P. 231

Computer Science  The major difference between the data   together to achieve the overall goal of
           abstraction  and process  abstraction  is
                                                     abstraction in  OOP. Data abstraction
           that data abstraction hides details about
                                                     ensures that data is accessed and modified
           data storage and manipulation, while
                                                     in a controlled manner, while process
           process  abstraction  hides  details  about
                                                     abstraction ensures that functionalities
          FOR ONLINE READING ONLY
           how actions are implemented.  For
           example, data abstraction is like hiding   are invoked and executed appropriately.
           the wires and internal components of a
           piano while providing knobs and buttons        Exercise 4.5
           for users. Process abstraction as shown   1.  Imagine a class called
           in Figure 4.9 is like pressing a “play”       “BankAccount”. Suggest the
           button on the piano without needing to        attributes that are expected for this
           know the mechanics of how the music           class.
           is played.                                2.  Describe how a principle of OOP
                                                         would assist you in restricting direct
                                   Private               access to the balance in your Bank
                               fill_fuel()               Account so that someone may not
                               create_spark()            change your account balance.
                               move_break_pads()
                               change_piston_speed()  3.  Recommend the methods to be
                                                         used in the class “BankAccount”
                                   Public                in order to control how the
                                 turn_on()               balance is accessed and modified,
                                 turn_off()              potentially adding security checks
             Car driver          break()                 or validations.
                                 gear_change()
                                                         Instead, the class would provide
                                                         methods like deposit() and
                                      Car
                                                         withdraw(). These methods would
                  Figure 4.9: Process abstraction        control how the balance is accessed
                                                         and modified, potentially adding
           The relationship between data abstraction     security checks or validations.
           and process abstraction is that both work


           Difference between OOP and Procedure Oriented Programming
           (POP)
           There are several differences between these two types of programming. Table 4.1
           shows the differences between them.







                                                 222
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   222                                                     23/07/2024   12:33
   226   227   228   229   230   231   232   233   234   235   236