Inheritance

In this example project, we’ll go through different forms of inheritance and how they work - including direct inheritance, abstract classes, and interfaces. This will give us a hands-on way to explore the use of inheritance in our code.

The next page will discuss the overall requirements that this example project should include. After that, there is a page for each programming language with some basic steps and a video to walk you through the whole process.

For these example projects, you’ll be given some starter code via the GitHub Classroom assignment, so make sure you’ve accepted the assignment and created your repository in GitHub first.

Good luck!

Subsections of Inheritance

Assignment Requirements

This page lists the example project requirements for Example 4 in CC 410. Read the requirements carefully and discuss any questions with the instructors or TAs.

Purpose

This example will cover adapting an existing project to use inheritance and interfaces

General Requirements

Warning

This project is the first that requires ALL general requirements introduced in the “Hello Real World” project. Read this section carefully to see what is required for this particular milestone.

  • All code must be object-oriented.
    • All executable code must be within a class
      • Python package files such as __init__.py and __main__.py are exempt.
    • Classes must be organized into packages based on common usage.
  • All projects must include automation for testing, style checking, and documentation generation.
    • Java: Use Gradle with the application, jacoco, and checkstyle plugins.
    • Python: Use tox configured to use Python 3.10 and a requirements file to install libraries.
  • All code must properly compile and be executable.
    • Java: It must compile and execute using Gradle.
    • Python: It must execute using Python 3.10. Where specified, type hints should be included in the code, and all code should pass a strict Mypy type check.
  • All code submitted must be free of style errors. We will be using the Google Style Guide for each language.
    • Java: Use Checkstyle 10.6.0+ and the Google Style Configuration .
      • You may modify the configuration to allow 4 space indentations instead of 2 space indentations.
    • Python: Use Flake8 with the flake8-docstrings and pep8-naming plugins. Code should conform to PEP 8 style with Google style docstrings.
  • Where specified, code should contain appropriate unit tests that achieve the specified level of code coverage.
    • Java: Use JUnit 5. You may choose to use Hamcrest for assertions.
    • Python: Use pytest. You may choose to use Hamcrest for assertions.
  • Where specified, code should contain appropriate documentation comments following the language’s style guide.
    • In any class that should be documented, every method in that class should have complete documentation comments.
    • Java: Use javadoc to generate documentation.
    • Python: Use pdoc3 to generate documentation.
  • Submissions to Canvas should be tagged GitHub releases that are numbered according to Semantic Versioning .

Assignment Requirements

This milestone should include the following features:

  • Update all fruit classes to directly inherit from the Fruit abstract class.
    • The Fruit class should include an abstract getter for the name attribute that returns the name of the fruit.
  • Add an IBlendable interface that defines a blend() method, and all classes that include the blend() method should implement that interface.
  • Add a new Apple class that properly inherits the Fruit superclass and the IBlendable interface.
  • Update the main() method in the Main class to do the following:
    • Create a list containing an instance of each class implementing the IBlendable interface. The list should have the IBlendable data type.
    • Iterate through the list and call the blend method on each object.
    • If the object is a subclass of Fruit, print the name of the fruit before calling blend.

Time Requirements

Completing this project is estimated to require 1 hour.

Grading Rubric

This assignment will be graded based on the rubric below:

  • Fruit abstract class - 30%
  • Fruit classes properly inherit Fruit - 10%
  • IBlendable interface - 30%
  • Blendable classes properly implement IBlendable - 10%
  • Main method code - 20%

The following deductions apply:

  • Any portion of the project which will not compile (Java), pass a strict type check (Python), or execute properly will be given a grade of 0.

This is not an exhaustive list of possible deductions. The instructors will strive to provide reasonable and fair grading, but we can’t predict all possible defects. It is up to the student to ensure that the project is complete and correct before submission.

Submission

Submit this assignment by creating a release on GitHub and uploading the release URL to the assignment on Canvas. You should not submit this Codio project or mark it as complete in Codio, in case you need to come back to it and make changes later.

Java

YouTube Video

Resources

Outline

Here is a basic outline of the steps to follow to complete this example.

  1. Clone Starter Code from GitHub
git clone <url> java
  1. Install SDKMAN

Instructions

curl -s "https://get.sdkman.io" | bash
  1. Close and Reopen Terminal to load SDK Man

  2. Install Gradle

sdk install gradle 7.6
  1. Compile, Run & Test Existing Project
cd java
gradle run
gradle check
gradle javadoc
  1. Confirm that project runs, no style errors, and Javadoc generates properly.

  2. Follow the Video to Refactor the Code Continuously commit to Git as changes are made!

  3. Confirm that project runs and has no style errors other than comments.

  4. When complete, use Git to commit and push updated code.

git add .
git commit -m "Example Complete"
git push
  1. On GitHub, create a release tag and submit URL to Canvas for grading.

Python

YouTube Video

Resources

Outline

Here is a basic outline of the steps to follow to complete this example.

  1. Clone Starter Code from GitHub
git clone <url> python

2, Run Project

cd python
python3 -m src
  1. Install Tox
pip3 install tox
  1. Check & Test Existing Project
python3 -m tox
  1. Confirm that project runs, all unit tests pass, no style errors, no type errors, and documentation generates properly.

  2. Follow the Video to Refactor the Code Continuously commit to Git as changes are made!

  3. Confirm that project runs and has no style errors other than comments.

  4. When complete, use Git to commit and push updated code.

git add .
git commit -m "Example Complete"
git push
  1. On GitHub, create a release tag and submit URL to Canvas for grading.