Page 230 - Computer_Science_F5
P. 230

(b) Abstraction in OOP: Hiding      specific data structures or memory locations
                   complexity                     used behind the scenes.
              Abstraction is a fundamental
              principle in  OOP that allows                                   Private
              programmers to focus on the                                    Name:string           Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
              essential details of objects and                                  id: int
              their interactions, hiding away the                             Public
              underlying complexities. It is like                            get_name()
              creating a simplified user interface                          set_name(str)
              for a complex machine.                                          Public

                                                                               get_id()
              Objects  in an  OOP language         User program               set_id(int)
              provide an abstraction that hides                                Object
              the   internal   implementation
              details. Similar  to the coffee               Figure 4.8: Data abstraction
              machine in your kitchen, you just
              need to know which methods of           Example 4.1:
              the  object  are  available  to call   Imagine a Bank class with an attribute balance.
              and which input parameters           You can access and modify the balance using
              are  needed  to  trigger  a  specific   methods like deposit() and withdraw(), but
              operation.  But  you do not  need    you do not need to know how the balance is
              to understand how this method is     actually stored internally (such as, integer,
              implemented  and what kinds of       and floating-point number).
              actions it has to perform to create
              the expected result.                (ii) Process abstraction: This level focuses on
                                                  hiding the implementation details of how an
              (c) Levels of abstraction in            object performs an action. It›s like providing
                   OOP                            a  single  entry  point  (method)  for  a  specific
              Within the concept of abstraction   functionality  without  revealing  the complex
              in OOP, there are two main levels   steps involved in its execution.
              that address different aspects of
              hiding complexity:                      Example 4.2 :

              (i) Data  abstraction:  This  level,   Assume you have a  car  class that has a
              as  shown in  Figure  4.8  focuses   method  accelerate(). Calling this method
              on hiding the details of how data    initiates  the acceleration  process, but the
              is stored and manipulated within     student does not need to see the intricate
              an  object.  It›s like  providing  a   code involving engine control, fuel
              user interface for interacting with   injection, and transmission changes.
              data without needing to know the

                                                    221
               Student’s Book  Form Five



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