CCEA A-Level Software Systems Development CL4
Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures
Exception Handling and Managing Input and Output
Testing an Object Oriented Application
Graphical User Interface Objects and Events
Multiple Forms and Linking to Files
Designing, Testing and Evaluating an Event Driven Application
Reasons for Systems Development and Systems Methodologies
Managing Projects
Testing Strategies
Database Concepts and Entity Relationship Modelling
Normalisation and Structured Query Language
Project Management and the Systems Approach in Practice
Defining Requirements and Documenting the Design
Building a Desktop Solution with a Database
Testing and Evaluating the Solution
Objects, Classes and Data Structures
Getters, setters and validating an object's state
- 3 things to know
- AS Unit 1
Overview
Accessor method, mutator method and java naming convention for these two kinds of method.
What you need to know
Answer each one before you reveal it.
Why is a getter preferred to simply making the field public?
State the Java naming convention for getter and setter methods
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is an accessor method?
Model answer
An accessor method, usually called a getter, is a public method whose only job is to return the current value of a private attribute.
- 2
What is a mutator method?
Model answer
A mutator method, usually called a setter, receives a new value for a private attribute and stores it, normally only after checking that the value is acceptable.
- 3
State the Java naming convention for these two kinds of method.
Model answer
Java convention names a getter getAttribute and a setter setAttribute, and a getter for a boolean attribute is normally named isAttribute.
- 4
Why is a getter preferred to simply making the field public?
Model answer
A getter keeps the attribute private, so the class is free to validate, record, calculate or restructure the value behind the method, none of which is possible once outside code reads the field directly.
- 5
A setter is written as public void setAge(int a) { if (a >= 0 && a <= 120) { age = a; } }. What happens when setAge(-3) is called?
Model answer
The test fails because -3 is below zero, so the assignment never runs and the attribute age keeps whatever valid value it already held.
- 6
Criticise a setter that stores whatever value it is handed.
Model answer
A setter with no check adds a method call but no protection, so the attribute is effectively public and an invalid value still reaches the object.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Objects, Classes and Data Structures, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.