Object-Oriented Approach 1: Enums and Interfaces
o Interfaces revealing only method signatures o Abstract base classes
Learning Outcomes
Create an enum
Create an interface
Create an abstract class
Resources
The Java™ Tutorials
Videos
Enum Types: Basic and Advanced Usage (19:20) what enum replaces, generate switch, instanceof, Enum class, constructor, methods, generate getters and setters, override toString, name
Interfaces (19:15) generate constructor using fields, Machine, Person, bank account analogy
Abstract Classes (12:58)
Static (and Final) (19:46)
Exam Topics
Create and use enumerations
Create and use interfaces, identify functional interfaces, and utilize private, static, and default methods
Oracle Academy
2 Class Design and Exceptions
2-1: Inheritance - Working with Pre-Written Code
Textbook
8 Classes and Objects: A Deeper Look
10 Object-Oriented Programming: Interfaces (10.9 and 10.10)
Tutorial / Practice Activity
2-1 Practice: JavaBank, Bike Project, Calculator
JavaBank, you can create a new project in IntelliJ and drag in the java files
Calculator
Lesson Plan
Mindfulness
Previous week review
Repl.it
Resource reinforcement and clarification
Object class vs driver class
enum
Represents a fixed set of special objects (enum constants)
All instances of the class are created in the class
Simple usage - just objects
In IntelliJ:
Right click src, new -> class -> kind: enum
Enter switch (myEnumVar) and press Alt+Enter to Create missing 'switch' branches
Class Enum methods
enum constant value accessible with name method
Class diagram, inherits from Enum
More complicated example - constructor, methods
From Planet example MERCURY (3.303e+23, 2.4397e6) is like Planet MERCURY = new Planet(3.303e+23, 2.4397e6);
Interface
Like a contract.
Variables declared in an interface are implicitly public static final.
Use when classes that implement aren't related.
Functional interface
Abstract Class
A class that can't be used to make objects.
Use when classes that extend will be somewhat related.
Mindfulness
How?
It starts with breathing. The most basic way to do mindful breathing is simply to focus your attention on your breath, the inhale and exhale.
Mindful breathing Stop Breathe Think