Git Product home page Git Product logo

java-inner-classes's Introduction

Java-Inner-Classes

Objectives

  • After this lab students should be able to implement interfaces in inner classes.
  • Attempting this lab challenges students to decipher implicit details from vague requirements, a common task in the professional world.

Unit Tests

You should write unit tests as you develop your program. Remember to use the tests to guide your development process, and be sure to test both that your classes do what they should do, and that they don't do what they should not do. Some examples of what you should test include:

  • Getting connections from the ConnectionManager
  • Requesting too many connections
  • Getting field values from a requested connection
  • Getting (invalid) field values from a closed connection

##Instructions

Part I: Return of the Connection Manager

Define a Connection interface with accessors for IP, Port, and Protocol, as well as a connect() method that returns a String. An example of this String for a connection to IP address 127.0.0.1 on port 8000 over HTTP would be "Connected to 127.0.0.1:8000 via HTTP.". Feel free to get creative with formatting as long as all connection information is provided in the connection String.

Create a ConnectionManager class with a private nested ManagedConnection class that implements Connection. ManagedConnecions are a special type of connection which is monitored and managed by ConnectionManager. There may be other types of Connections out there, but we're not worried about implementing them here.

ConnectionManager behaves like a factory for Connections, and should have methods to get connection objects based on IP and protocol (You must support at least three protocols from this list) or custom-configured connections based on IP and port number with optional protocol (the default protocol should be HTTP)

The ConnectionManager can only handle so many connections (You can set this limit in the constructor). ConnectionManager should keep track of how many connections it has initialized; if it has reached its limit and another request for a connection comes in, ConnectionManager should return null instead of a Connection object.

Part II: Closing Connections

When you're done with a connection, you really should clean up after yourself. Implement the java.io.Closeable interface and add a close() method to the Connection interface and to your nested ManagedConnection class. A ManagedConnection object should tell its ConnectionManager that it has been closed, so that the ConnectionManager knows that there is one more connection available on the system.

A Connection should not provide its IP or Port numbers once it has been closed. Add logic to your implementation so that the accessors for these values return invalid values (i.e.: error codes) if the connection has been closed. The connect() method should also return an error message if it is called after a connection has been closed.

Additional Practice

If you are having trouble with this lab:

  • try Exercise 1 from the Inner Classes chapter in Thinking In Java.
  • Build your domain knowledge by readin up on TCP/IP networks here
  • Read through the Oracle Nested Class Tutorial

java-inner-classes's People

Contributors

rjackson88 avatar davidginzberg avatar

Watchers

James Cloos 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.