UML Class Diagrams

Notation & Visibility
ClassName

- privateAttribute: type

+ publicAttribute: type

+ constructor(params)

+ publicMethod(): returnType

- privateMethod()

Inheritance

Represented by a solid line with a hollow arrow pointing from the Subclass to the Superclass.

Array of Objects

Indicated by a relationship line between classes to show that one class contains a collection (array) of another.

Logic Design

Top-Level Design

The main steps of the program without detail.

1. Get user details (OUT: details)
2. Process data (IN: details, OUT: result)
3. Display result (IN: result)
Data Flow

Shows how data moves between modules (Parameters/Returns).

Refinements

Detailed pseudocode for complex steps identified in the top-level design.

Structures

2-D Arrays

A grid of data (rows/columns).

grid = [[1, 2], [3, 4]]
val = grid[row][col]
Bulk Create Objects
carList = []
for i in range(1000):
  new_car = Car(f"C_{i}", 10000)
  carList.append(new_car)

Advanced OOP

Method Overriding

A subclass creates its own version of a method already defined in its superclass. This allows for specific behavior.

Polymorphism (Array of Objects)

An array defined by the superclass type can store objects from any of its subclasses.

Critical Constraint:

When iterating through this array, you can only call methods defined in the superclass. A subclass cannot execute its own unique methods unless they were inherited/overridden from the superclass.

  • The system checks the actual class of the object at runtime.
  • It executes the overridden method in the subclass.
# Superclass: Animal | Subclasses: Dog, Cat
pets = [Dog(), Cat()]

for p in pets:
  p.makeSound()
  # OK: defined in Animal
  # p.wagTail() -> ERROR
  # (if wagTail is ONLY in Dog subclass)

Linked Lists

Structure & Pointers

A dynamic structure where nodes are linked by pointers.

  • Head: Pointer to the first node. If None, the list is empty.
  • Tail: Optional pointer to the last node. Useful for appending efficiently.
  • Node: Contains Data and Next (pointer).
Head
[D | P]
[D | P]
Tail
Common Operations

Insert (at start):

  1. Create new node.
  2. NewNode.Next = Head.
  3. Head = NewNode.

Remove (from start):

  1. Store reference to first node.
  2. Head = Head.Next.
  3. Delete stored node.
Double Linked List

Each node has Next and Previous pointers. Essential trackers:

  • Head: Points to the first node.
  • Tail: Points to the last node.
Head
[P|D|N]
[P|D|N]
Tail
Traversal

Use a temporary pointer (current). Start at Head, move to current.Next until None.

MySQL Integration Code

Connection & Query
import mysql.connector

# 1. Open Connection
db = mysql.connector.connect(
  host="localhost",
  user="root",
  password="password",
  database="school_db"
)
cursor = db.cursor()

# 2. Execute SQL (%s placeholder)
sql = "SELECT * FROM Users WHERE age > %s"
cursor.execute(sql, (18,))

# 3. Close Connection
db.close()
Formatting Results
# Fetch all results
results = cursor.fetchall()

for row in results:
  name = row[0]
  score = row[1]
  print(f"{name}: {score}")

# Use fetchone() for 1 result
user = cursor.fetchone()

Wireframing

Plan the interface layout and navigation before coding.

  • Show position of Input and Output.
  • Identify User Actions (Buttons/Clicks).
  • Indicate Validation (e.g., "Must be numeric").
  • Detail Navigation paths to other screens.