Coder Social home page Coder Social logo

02-classes-interfaces's Introduction

This is an assignment to the class Programmieren 3 at the University of Applied Sciences Rosenheim.

Assignment 2: Classes and interfaces revisited

In this assignment we'll be looking at

  • static and regular inner classes
  • anonymous classes
  • lambda expressions and @FunctionalInterface by implementing a basic linked list.

A linked list consists of a controller (the list class) and elements that contain the actual payload (the container or element class). The controller class maintains a reference to the first list element (head), and every element points to its successor (or to a null value, if it's the last). The following UML shows all classes of this assignment (including the interfaces java.util.Iterator<T> and java.lang.Iterable<T>; we'll cover ).

Note: the concept of an iterator will be discussed in detail in a few weeks.

Classes

Setup

  1. Create a fork of this repository.
  2. Clone your fork to get a local working copy.
  3. Import the project to your IDE (choose Gradle project)

Static and regular inner classes

  1. What is a static class?
    • Refresh your knowledge on UML (e.g. here)
    • What's the difference between a regular inner and static inner class?
    • Can you think of some use cases for both?
  2. Implement Element as static inner class of SimpleListImpl.
    • Why is this class static, and ideally private?
  3. Implement the Iterator interface as inner class of SimpleListImpl.
    • Why is it helpful to make this class non-static?
  4. Add the Iterable interface to your SimpleListImpl, and implement the required methods.
    • Why is implementing the Iterable interface essential for a (good) list implementation? (Hint: Check the test cases!)
    • Are there any language definition constraints to this?

Anonymous (inner) classes and lambda expressions

  1. Implement the filter method for your SimpleListImpl class (see SimpleFilter interface).
  2. Check the given test suite for an example on
    • how to use an anonymous class with an interface.
    • how an anonymous class can be replaced by a lambda expression.
  3. Add some test methods and implement another filter logic (e.g. every third number, or any number smaller than a certain value).
  4. Review anonymous classes and lambdas.
    • Lambda expressions look very convenient; can you think of a scenario where they should not be used?
    • Recall how scoping works for anonymous (inner or local) classes; can you think of a scenario where to avoid them?

02-classes-interfaces's People

Contributors

sikoried avatar prskr avatar gitguddy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.