Skip to content

Commit

Permalink
iluwatar#90 Added comments for the example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
iluwatar committed Jul 19, 2015
1 parent c455656 commit a9fa304
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 1 deletion.
18 changes: 18 additions & 0 deletions front-controller/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* Command for archers.
*
*/
public class ArcherCommand implements Command {

@Override
Expand Down
5 changes: 5 additions & 0 deletions front-controller/src/main/java/com/iluwatar/ArcherView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* View for archers.
*
*/
public class ArcherView implements View {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* Command for catapults.
*
*/
public class CatapultCommand implements Command {

@Override
Expand Down
5 changes: 5 additions & 0 deletions front-controller/src/main/java/com/iluwatar/CatapultView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* View for catapults.
*
*/
public class CatapultView implements View {

@Override
Expand Down
5 changes: 5 additions & 0 deletions front-controller/src/main/java/com/iluwatar/Command.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* Commands are the intermediary between requests and views.
*
*/
public interface Command {

void process();
Expand Down
14 changes: 14 additions & 0 deletions front-controller/src/main/java/com/iluwatar/ErrorView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.iluwatar;

/**
*
* View for errors.
*
*/
public class ErrorView implements View {

@Override
public void display() {
System.out.println("Error 500");
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
5 changes: 5 additions & 0 deletions front-controller/src/main/java/com/iluwatar/View.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.iluwatar;

/**
*
* Views are the representations rendered for the user.
*
*/
public interface View {

void display();
Expand Down

0 comments on commit a9fa304

Please sign in to comment.