Object-Oriented Approach 1: Enums and Interfaces

o Interfaces revealing only method signatures o Abstract base classes

Learning Outcomes

  1. Create an enum

  2. Create an interface

  3. Create an abstract class


Resources

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

  • Practice Quiz on Interfaces

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