#90 Added comments for the example code.

This commit is contained in:
Ilkka Seppala 2015-07-19 13:54:07 +03:00
parent c4556561c4
commit a9fa304690
10 changed files with 74 additions and 1 deletions

View File

@ -1,5 +1,23 @@
package com.iluwatar;
/**
*
* The Front Controller is a presentation tier pattern. Essentially it defines a
* controller that handles all requests for a web site.
*
* The Front Controller pattern consolidates request handling through a single handler
* object (FrontController). This object can carry out the common the behavior such as
* authorization, request logging and routing requests to corresponding views.
*
* Typically the requests are mapped to command objects (Command) which then display
* the correct view (View).
*
* In this example we have implemented two views: ArcherView and CatapultView. These
* are displayed by sending correct request to the FrontController object. For example,
* the ArcherView gets displayed when FrontController receives request "Archer". When
* the request is unknown, we display the error view (ErrorView).
*
*/
public class App {
public static void main(String[] args) {

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Command for archers.
*
*/
public class ArcherCommand implements Command {
@Override

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* View for archers.
*
*/
public class ArcherView implements View {
@Override

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Command for catapults.
*
*/
public class CatapultCommand implements Command {
@Override

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* View for catapults.
*
*/
public class CatapultView implements View {
@Override

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Commands are the intermediary between requests and views.
*
*/
public interface Command {
void process();

View File

@ -0,0 +1,14 @@
package com.iluwatar;
/**
*
* View for errors.
*
*/
public class ErrorView implements View {
@Override
public void display() {
System.out.println("Error 500");
}
}

View File

@ -1,5 +1,11 @@
package com.iluwatar;
/**
*
* FrontController is the handler class that takes in all the requests and
* renders the correct response.
*
*/
public class FrontController {
public void handleRequest(String request) {

View File

@ -1,9 +1,14 @@
package com.iluwatar;
/**
*
* Default command in case the mapping is not successful.
*
*/
public class UnknownCommand implements Command {
@Override
public void process() {
System.out.println("Error 500");
new ErrorView().display();
}
}

View File

@ -1,5 +1,10 @@
package com.iluwatar;
/**
*
* Views are the representations rendered for the user.
*
*/
public interface View {
void display();