Advanced concepts in Object-Oriented Programming, Data Structures, and Database Integration.
1. Advanced Design & UML
UML Class Diagrams
- privateAttribute: type
+ publicAttribute: type
+ constructor(params)
+ publicMethod(): returnType
- privateMethod()
Represented by a solid line with a hollow arrow pointing from the Subclass to the Superclass.
Indicated by a relationship line between classes to show that one class contains a collection (array) of another.
Logic Design
The main steps of the program without detail.
2. Process data (IN: details, OUT: result)
3. Display result (IN: result)
Shows how data moves between modules (Parameters/Returns).
Detailed pseudocode for complex steps identified in the top-level design.
2. Implementation & OOP Concepts
Structures
A grid of data (rows/columns).
val = grid[row][col]
for i in range(1000):
new_car = Car(f"C_{i}", 10000)
carList.append(new_car)
Advanced OOP
A subclass creates its own version of a method already defined in its superclass. This allows for specific behavior.
An array defined by the superclass type can store objects from any of its subclasses.
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.
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
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
DataandNext(pointer).
Insert (at start):
- Create new node.
- NewNode.Next = Head.
- Head = NewNode.
Remove (from start):
- Store reference to first node.
- Head = Head.Next.
- Delete stored node.
Each node has Next and Previous pointers. Essential trackers:
- Head: Points to the first node.
- Tail: Points to the last node.
Use a temporary pointer (current). Start at Head, move to current.Next until None.
3. Database Integration (Python & MySQL)
MySQL Integration Code
# 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()
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.