APCS Unit 4
Object Oriented Design
Object Oriented Design Introduction
Welcome to Unit 4

With everything we now know about creating basic programs and controlling the flow of the program with control structures, it might feel like the only thing left is to be patient and make larger and larger programs with more and more complex for loops and if statements.  That’s potentially possible, but Java (and other modern high-level languages) make something called Object Oriented Programming (OOP) possible. In this next unit, we get to look at how to create our own classes, and our own larger programs that can create their own objects similar to how we made multiple Jeroos many weeks ago.

   In this unit, you’ll learn the details of:

  1. Making and using your own classes, methods, and objects
  2. Using constructors to set instance variables
  3. How classes and objects relate to each other

In the end, you’ll have an awesome set of new tools for organizing your programs in more efficient and effective ways!

 

Part 1: Classes & Constructors

Class & Constructor Example

A constructor is the method in a class that sets all the instance variables.  In this first part of the unit, your job is to get used to making constructors and setting up new classes.  Each of these will really only have 3 parts:

  1. The class signature
  2. The private instance variables
  3. The constructor to set those variables

As you work through the tasks for Part 1, be looking for patterns and thinking about ways that you could organize more complex information in cool ways!

GRADING & PROCESS

 Take a page of notes on Object Oriented Design and the presentations below

 Complete the 6 Java tasks about constructors

 Complete 6 challenges in the Java -> Warm-Up 1 section on codingbat.com

 Have Mr. Benshoof check off your completed tasks 

Constructors 1

Constructors 2

Constructors 3

Part 2: Getters, Setters & Mutators

Example Getters & Setters

The second part of this unit is about writing methods that can let a class interact with another calss’s variables. Since we make the variables in a class PRIVATE, other classes are not able to reach in and see what they are without asking.  In order for them to ask what a variable equals – or to change the value of a variable – we need to make methods that can facilitate that interaction.  These methods are called “Setters” and “Getters”.

SETTERS are methods that let another class SET the value of a variable.  These have a return type of ‘void’ and are just used to set or reset an object’s instance variable.  This is like the phone company changing your phone number:  they need to SET your new phone number, so they do it.

GETTERS are methods that let another class GET the value of a variable.  These have a return type that matches they variable type of the thing being asked for.  It’s like someone asking you for your phone number: they want to GET your phone number, so you RETURN it to them.

GRADING & PROCESS

 Take a page of notes on Object Oriented Design and the presentations below about setters and getters

 Complete the 8 Java tasks about setters & getters

 Complete 6 challenges in the Java -> String 1 section on codingbat.com

 Have Mr. Benshoof check off your completed tasks

Getters & Setters

More About Methods

Part 3: LHS Zoo

Example Class Structure

The final part of our unit has us combine the ideas of multiple classes within a single program to design the structure of a program to keep track of Lathrop's new zoo! Here you'll get the chance to practice the class building ideas we've covered in the first two parts of the unit.  As you develop your program, the real emphasis is supposed to be on the organization and structure of a larger program.  Because of this, you don't need to spend too much time trying to make things connect and print properly - instead, focus on the interaction between objects!  Have fun and be creative.

GRADING & PROCESS

 Brainstorm ideas for the classes and structure of your LHS Zoo program

 Create your LHS Zoo Program

 Write APCS Log 4: Object Oriented Design

APCS Unit 4 Map
Looking for something?  Here you'll find a library of links to all the documents, images, and videos needed here in APCS Unit 4.