Confusion with the new project

I am writing all of this in one topic because it seems ( at least for me) to be connected to each other.

I have some Problems understanding the new project. I first thought that the .java file in the URI folder were the correct implementation and the two subfolders in URI ( implementation and test) were our assignments. however while Inspecting SimpleTests.java I noticed a few things:

1: The test “testIPv4AdressSimple” parses the URI “scheme://1.2.3.4”. and gets the host. folowing the Grammar i thought that the host in this case should be the IPv4Adress 1.2.3.4 . However the test asumes that the host is not an IP Adress.

2: The file UriParserFactory.java has a TODO despite being in the folder URI and not in the folder implementation. It states that we should create a UriParser implementation similar to the examples in the package uri.implementation. But isnt the package uri.implementation our tasks 2? how would I be able to do task 1 first and then task 2 if the first task requires the first to be done?

3: All other files in folder URI dont contain a TODO but also dont contain an implementation.

4: The UriParserFactory should return a UriParser instance. but a Uri Parser returns an Uri. Isnt one of the two redundant? And how doeas this returned Uri even look like? is it the input string? or is it the input string divided in more than one input string and put into an aray?

5 Likes

The Java files Host, IPv4Address, Uri and UriParser are interfaces, they do not contain any implementation details, instead they specify which methods you need to provide in your implementations of them and what the signatures are. They together with the fact that there is a class called UriParserFactory with a method of the signature:

public static UriParser create(String uri)

are the only thing that your implementation, the reference implementation and any broken implementation have in common. Any changes to the method signatures therein mean that the tests on the server might not run or do something unexpected.

Now the tests on the server do not know what your classes implementing those four interfaces are. In fact the comments in the provided implementation classes tell you that you can also create other implementations. That is: you could delete e.g. HostImplementation.java and create something called HostWhatever.java which implements the interface Host and use that to finish the project. This does not matter to the test server at all.

The problem now is: how does the test server call the functions you created? Well that is what the factory is for. You provide a UriParserFactory.java and in it you create an instance of your implementation of the interface UriParser.
On the test server they can then use your UriParserFactory.java in order to test your implementation OR they could replace your UriParserFactory.java by a file of the same name which creates an instance of another class which implements the interface UriParser.

So essentially this “factory” allows them to switch out one implementation for another in order to test any of these implementations:

  1. Reference Implementation
  2. Your Implementation
  3. Broken Implementation (Part 1 of the project)

against any of these tests:

  1. eval tests
  2. Your tests

without there being any dependence on how the implementations of the four classes are actually called or how many other classes are created to make the project work.

The create method in your factory is not meant to implement any parsing at all. It is essentially just you calling the constructor for your class implementing the interface UriParser. (and I guess it can’t hurt to check if the input string is null, but you could also do that in the constructor of your implementation)

I guess that also partially answers your fourth question but if not then maybe this helps: The Uri that the parser returns is an instance of your class implementing the interface Uri and so most definitely not a String. How you store the information in your class is up to you. You could have a String field called “scheme” and a String field “userInfo” or a List holding both at once. It does not matter and is your choice completely (with the caveat that some choices are worse than others).

3 Likes

This might be part of the solution I was looking for. To check if it is i might summarize your explanation to this short answer : the tests we should write in task 1 as well as the evaluation tests of tasks 2 should only call the uriparserfactory with a string and use the functions provided in the interfaces to get a result in form of a string.
The ONLY exception might be if we want to compare the octects of a IPv4 address. Iff all of this is correct then my points 3 and 4 are indeed answered.

No, the way you check the octets is by using SimpleTests#getIPv4Octets(Host).

Wich uses a function from the IPv4Adress interface.

Thanks for the great help so far.

Well, yes, but I don’t see the issue? Using that function is fine, why wouldn’t it be?