Lesson 3.2: Impact of Program Design

Unit 3 · Lesson 3.2 · Conceptual

Lesson 3.2: Impact of Program Design

🕑 20–25 min· 8 Practice Questions· 4 Mastery Questions· Output Predictor + Bug Hunt

What You'll Learn

  • Explain how design choices affect security, privacy, and maintainability
  • Distinguish between preconditions and postconditions
  • Describe ethical implications of storing unnecessary data
  • Identify side effects in void methods

Key Vocabulary

Term Definition
encapsulation Bundling data and behaviors into a class; protecting data from direct external access
precondition A condition that must be true before a method is called for it to work correctly
postcondition A condition guaranteed to be true after a method successfully executes
side effect Any change to program state beyond a method's primary return value
data integrity Assurance that data remains valid, consistent, and uncorrupted
data minimization Principle of collecting only data that is necessary for the app's function
maintainability How easily a program can be modified, debugged, or extended over time

CED EK 3.2 — Social/Ethical Implications

Design choices affect reliability, security, privacy, and maintainability. EK 3.2 focuses on Skill 5.A: explaining how computing impacts society, economy, and culture.

Why Design Choices Matter

Bank Account: Bad vs Good Design

Bad: public double balance; — any class can write myAccount.balance = -999999.0;

Good:

public class BankAccount {
    private double balance;
    public void deposit(double amount) {
        if (amount > 0) balance += amount;
    }
}

The mutator enforces the precondition that amount must be positive.

Preconditions and Postconditions

Precondition Documentation

// Precondition:  amount > 0
// Postcondition: balance is increased by amount
public void deposit(double amount) {
    balance += amount;  // trusts the precondition
}

On the AP exam, preconditions appear as comments. If a precondition is violated by the caller, the method's behavior is undefined.

Social and Ethical Implications

Design Decision Real-World Impact
Public instance variables Any class can corrupt object state without validation
No input validation Negative ages, impossible balances crash programs or corrupt data
Storing unnecessary personal data Increases privacy risk; data breaches expose more user info
Hard-coded values everywhere Makes maintenance harder; one change requires hunting through all code

AP Trap: Precondition vs Defensive Code

If a method header says Precondition: n > 0, you do NOT need an if check inside. The precondition tells the CALLER to ensure it's true. Adding defensive code won't lose points, but the exam doesn't require it.

AP Trap: Side Effects in Void Methods

A void method can change program state by modifying instance variables. incrementCounter() changes state even without returning a value.

AP Trap: Private Does NOT Mean Inaccessible

Private instance variables can be read and changed inside the class by any of its methods. 'Private' only restricts access from outside the class.

Real-World Connection: HIPAA medical privacy laws exist because healthcare software made data too accessible. Making patient records 'public' in software is legally and ethically unacceptable.

Summary

  • Design choices affect security, privacy, and maintainability.
  • Public instance variables allow any code to corrupt object state -- always use private.
  • A precondition must be true when a method is called; it is a contract with the caller, not enforced by Java.
  • Void methods can have significant side effects by modifying instance variables.
  • Data minimization: collect only what is necessary for the app's function.
Tier 2 · AP Practice

Practice Questions

MCQ 1
The following class has a design problem.
public class Patient {
    public String medicalHistory;
    public int patientId;
}
Which BEST describes the problem?
A The class is missing a constructor
B The class is missing a toString() method
C Public instance variables allow any class to access or modify sensitive data directly
D The class has too few instance variables
C is correct. Public instance variables break encapsulation, exposing medicalHistory to any class.
MCQ 2
A method has // Precondition: quantity >= 0 and assigns this.quantity = quantity;. Which is TRUE?
A The method is correct; the caller guarantees quantity >= 0
B The method must throw an exception when quantity < 0
C The method should use a loop to validate quantity
D The precondition causes automatic rejection of invalid values
A is correct. A precondition is a contract with the caller. No internal defensive code required on the AP exam.
MCQ 3
Which design choice BEST protects data integrity?
A Declaring all instance variables as public
B Using only static variables
C Writing methods with no parameters
D Declaring instance variables private and providing validated mutator methods
D is correct. Private variables + validated mutators prevent invalid state.
MCQ 4
A social media platform stores: username, password (hashed), birth date, location, and full browsing history. Which practice is MOST concerning from a responsible computing perspective?
A Storing the username as a private String instance variable
B Retaining detailed browsing history indefinitely without user consent
C Using a hashed password instead of plain text
D Storing birth date as a separate attribute
B is correct. Retaining browsing history indefinitely without consent violates data minimization and raises privacy risks.
MCQ 5
A method adds a score to a list with no validation. Which improvement BEST protects integrity?
A Change parameter type from int to String
B Make the method return the new list size
C Add an if statement to only add when 0 <= score <= 100
D Declare the method static
C is correct. Validating range before inserting prevents invalid data. A, B, D don't prevent bad values.
MCQ 6
Which statement about side effects in Java methods is ACCURATE?
A Only methods that return a value can have side effects
B Void methods cannot change any instance variable
C A void method can modify instance variables, producing side effects without returning a value
D Side effects occur only in static methods
C is correct. Void mutator methods change state without returning anything -- that IS a side effect.
MCQ 7
Which of these are GOOD software design practices?
I. Declare targetTemp as private double
II. Provide setTargetTemp(double t) that only allows 60 <= t <= 85
III. Document "Precondition: 60 <= t <= 85" instead of checking inside
A I only
B I and II only
C I and III only
D I, II, and III
D is correct. All three are valid. I: private is best practice. II: validated mutators protect data. III: precondition documentation is also acceptable.
MCQ 8
A programmer decides whether to store precise GPS in a gaming app. What should be evaluated FIRST?
A Whether GPS data can be compressed
B Whether the user has consented and whether precise location is necessary for the app
C Whether Java supports double-precision floating-point for GPS
D Whether GPS should be a String or double array
B is correct. Responsible computing: collect only what is necessary and with consent. A, C, D are implementation details secondary to the ethical question.
PRACTICE WITH A GAME — CHOOSE ONE:
Output Predictor: Encapsulation
Predict the output.
Question 1 of 3  ·  Score: 0

Done!
You got 0 of 3 correct.
Bug Hunt: Encapsulation
Click the buggy line, or 'No bug'.
Question 1 of 3  ·  Score: 0
No bug — code is correct
Done!
You got 0 of 3 correct.
Tier 3 · AP Mastery

Mastery: Impact of Program Design

MCQ 1
A Vault class has private int combination and a method public boolean open(int attempt) { return attempt == combination; }. Which BEST describes the design benefit?
A External code can verify the combination without reading or changing the private variable
B The combination is now public because the method returns a boolean
C The method eliminates the need for a constructor
D The boolean return type makes the class immutable
A is correct. Encapsulation lets external code interact through a method while the actual value stays private.
MCQ 2
Which change MOST improves data integrity of public void setGpa(double g) { gpa = g; }?
A Change return type to double
B Declare the method static
C Add a condition that only updates gpa when 0.0 <= g <= 4.0
D Change parameter type to int
C is correct. Range validation prevents invalid GPA values from being stored.
MCQ 3
Which BEST explains why storing a user's precise home address in a gaming app raises an ethical concern?
A Precise addresses cannot be stored as String values
B The address is likely unnecessary for the game and creates an unneeded privacy risk
C Home addresses change too frequently
D Java prohibits storing personal data in instance variables
B is correct. Data minimization: collect only what is needed. A gaming app rarely needs a home address.
MCQ 4
A method has // Precondition: speed >= 0 and a programmer calls car.setSpeed(-50). What happens?
A Java throws an exception automatically because of the precondition comment
B The compiler refuses to compile because preconditions enforce type safety
C The method executes and sets speed to -50; Java does not enforce precondition comments
D The precondition comment causes the method to be skipped
C is correct. Java does not enforce precondition comments. The method will execute and set speed to -50. The precondition is a contract for the programmer, not the JVM.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]