Object Oriented Programming

Cards (52)

  • In Procedural Programming, the programmer concentrates on the steps that must be undertaken to solve the problem rather than the data and operations.
  • Structured Programming is a type of procedural programming where a programmer uses a limited set of control structures to construct the program.
  • Hierarchy / Structure Charts use a top-down approach to explain how a program is put together.
  • The difference between procedural programming and object-oriented programming is that procedural programming separately stores the code and the data operated on whereas object-oriented programming combines all the data and processes into a single object.
  • The four major principles of object-oriented programming are:
    • Abstraction
    • Encapsulation
    • Inheritance
    • Polymorphism
  • An abstract data type is a mathematical model for data types where a data type is defined by its behaviour from the point of view of the user of the data. (possible values, operations, and behaviour)
  • Types of Class Member Visibility:
    • Public
    • Private
    • Protected
  • Public variables and methods are visible in code external to the class.
  • Private variables and methods are visible in code within the class.
  • Protected variables and methods are visible within the class in which they are declared and all subclasses of that class.
  • Input the correct terms:
    A) Visibility
    B) Class Name
    C) Attributes
    D) Methods
  • In Unified Modelling Language, the symbols representing member access specifiers are:
    + public
    - private
    # protected
  • An instance variable stores data which describes an individual object. Hence, memory space will be allocated for that variable every time a new object is created.
  • A class variable stores data which has the same value in all methods and can be accessed by every object belonging to that class, hence there will only be one copy of a class variable in existence.
  • Instantiation is the creation of a real instance for particular realisation of an abstraction or template such as a class of objects or a computer process.
  • Constructor is a procedure that creates objects from a class definition. It initialises data members, making dynamic memory allocation requests, and opening files or communication sockets.
  • Destructor is a method which is invoked when the object is going to destroy itself. It happens when its lifetime is bound to scope and its execution leaves the scope.
  • Destructors are mainly used to free resources (memory, open files or sockets, database connections, etc.) to prevent memory leakage.
  • A constructor in a class is a special type of method called to initialise an object.
  • Constructor methods are called when an object is created, while destructor methods are called when an object goes out of scope.
  • Destructors may not exist in languages with garbage collection.
  • An object is a particular instance of a class which is a collection of data and operations that act on said data.
  • Properties of Objects:
    • Data members describe the state of the object
    • Methods describe the behaviour of the object
    • It has memory allocated to it to record its state
    • The operations are methods defined in the class/inherited from superclasses
    • The process of creating an object is known as instantiation
    • It responds to messages passed to it
  • Input the correct terms:
    A) Object Name
    B) Class Name
    C) Object Variables
    D) Visibility
  • A method is a function that belongs to a class, which includes a method signature composing of a method name, number and type of parameters, and return type.
    FUNCTION <name>(<parameter> : <data type>) RETURNS <return type>
  • An instance method is used to manipulate instance variables in an object, and can only be called through instances of a class or a subclass.
  • Accessor methods are used solely to retrieve data member values from within an object, commonly known as getters.
  • Mutator methods are used to change the value of data members and are commonly known as setters.
  • Mutator methods accept arguments whereas accessor methods usually possess a return type reflecting the data member that they are to convey back to the caller. Both are public methods to facilitate invocation through the object.
  • Class methods only manipulate class variables and not instance variables, and can be executed without creating any instances.
  • Instance methods operate on instances of a class, and are typically concerned with the manipulation of instance variables, while Class methods are typically concerned with the manipulation of class variables, and do not require the existence of any instance to operate.
  • Support methods which are typically set with private or protected visibility, are used to assist other methods in performing internal tasks but are unavailable to call through the object.
  • Service methods which are typically set with public visibility, provides services to the user of an object, and may be called through the public interface of an object.
  • Encapsulation is achieved when each object keeps its state private inside a class. They are only accessible via public methods.
  • Encapsulation is used to restrict access to data and methods in order to prevent them from being modified by accident.
  • Encapsulation is used as an information hiding mechanism, where the data structure of the class is hidden, with only a public interface provided by methods.
  • Data hiding hides internal object details and prevent unintended changes by ensuring exclusive data access to class members and protecting object integrity.
  • Data hiding is a mechanism for hiding the details of the implementation of an object from the code that uses it.
  • Data hiding prevents external code from accessing internal methods and data members of a class, preventing access to partial information and ensuring contracts between the provider of a class and user are fulfilled.
  • Abstraction is used to hide internal details and only show functionalities. It is achieve through encapsulation.