Encapsulation (OOP) (OCR A-Level Computer Science): Flashcards

📚Flashcards
Encapsulation (OOP)
Sign up to keep revising.Create a free account to study more flashcards and track your progress.

Practise the cards

13 cards from this deck

Show

Definition of encapsulation

Restricts direct access to object's data & methods, ensures controlled modifications

3 things encapsulation enhances

Data security, modularity, code maintainability

Where are private attributes accessible?

Only within the class

Python private attribute symbols

Leading _ or double __

Purpose of public methods

Allow controlled access to private attributes

Getter methods function

Retrieve value of private attributes (read-only access)

Setter methods function

Allow controlled modification with validation

Encapsulation data security benefit

Prevents unauthorised modifications, protects integrity

Validation in setters ensures

Data stays consistent and valid

Modularity benefit of encapsulation

Groups related data & methods within class

Encapsulation mistake: direct access

Modifying private attributes from outside class causes error

Encapsulation mistake: no validation

Can lead to invalid data, compromises data integrity

Ease of maintenance benefit

Changes isolated within class, doesn't affect external code

Join 100,000+ A-Level students studying Flashcards with us.

Select your subjects, and get access to A+ resources today.