Object-Oriented Programming and PC Architecture

Object-Oriented Programming

Purpose: To manage complex data structures and programs within an organized framework. A data object is not simple; it contains several well-structured components.

Class

Classes are object declarations, also definable as object abstractions. A class is a static construct describing common behavior and attributes. It’s formalized through a data structure, including data and functions called methods. Methods define behavior. Every class has two key methods:

  • Constructor: Called when the class is instantiated in memory. It initializes values and often calls constructors of other classes.
  • Destructor: Called at the end of a class instance’s lifespan to free resources.

Objects are instances of a class. Creating an object from a class is called instantiation.

  • Identity: Distinguishes one instance from another.
  • Behavior: Enables objects of the same class to perform specific tasks.
  • State: Determined by stored information, which can be fixed or variable.

Data Abstraction

Allows ignoring non-essential details. Present in almost all programming languages (e.g., data structures, data types, procedures, and functions). It’s an object’s ability to function independently of its context.

Encapsulation

The ability to respond to requests through methods without revealing the internal workings.

Static attributes are common to all class instances. Static methods can be invoked without instantiating the class and only access static data. They are often used for class initialization.

Inheritance

A class can inherit variables and methods to subclasses (the inherited class is the superclass or parent class). A subclass possesses its attributes and methods and inherits those of the superclass, creating an inheritance hierarchy.

Polymorphism

The ability to define multiple operations with the same name, differentiated by input parameters. The operation performed depends on the input object. Polymorphism also refers to creating different objects using the same base class.

Abstract Classes

Abstract methods are declared but not implemented. A class with an abstract method is an abstract class and cannot be instantiated. They define a framework to be completed in subclasses.

PC Architecture

Hardware

The physical components of a computer, whose functionality is not easily changed. A computer has four basic units:

  1. Input Unit: Receives data and instructions. Consists of one or more devices.
  2. Central Processing Unit (CPU): Processes data. Contains three main units:
    • Control Unit: Manages data and instruction transfer.
    • Arithmetic Logic Unit (ALU): Performs arithmetic, logical, and relational operations.
    • Registers: Temporarily store instructions and data.
  3. Memory Unit: Stores programs and data.
  4. Output Unit: Displays results.

Internal Data Representation

  • Bits & Bytes: Data is represented using 0s and 1s (bits). 8 bits form a byte.

Software

Programs directing hardware operations, easily modifiable.

Operating System (OS)

Manages computer resources and provides a hardware interface. It organizes storage using:

  • Directories: Logical entities for hierarchical information organization. They don’t contain information themselves.
  • Files: Logical entities containing information of various types.

Applications

Programs performing specific tasks (databases, scientific computing, word processing, etc.).

Systems Development

Program sets for application generation. Classified by:

  1. Level of Abstraction:
    • Low-level: Programmer specifies hardware-close tasks.
    • High-level: Programmer manipulates abstract entities.
  2. Methodologies:
    • Imperative: Programmer specifies program flow.
    • Declarative: Programmer defines the problem, the language handles the solution.
    • Object-oriented: Programmer defines entities with internal states and modification mechanisms.
    • Mixed: Combines methodologies.
  3. Program Execution:
    • Interpreted: Translated during execution.
    • Compiled: Translated before execution.
    • Programming Environment: Rich environments for development, debugging, and testing.

C Language

  1. Disadvantages:
    • Lack of I/O and string handling instructions, relying on libraries, impacting portability.
    • Excessive freedom can lead to subtle errors.
    • Operator precedence can make expressions complex.
  2. Characteristics:
    • Structured programming
    • Concise expressions
    • High- and low-level coding
    • Replaces assembly language
    • Utilizes system primitives
    • Not domain-specific
    • Highly optimized object code