Skip to content

Commit a9fa304

Browse files
committed
iluwatar#90 Added comments for the example code.
1 parent c455656 commit a9fa304

File tree

10 files changed

+74
-1
lines changed

10 files changed

+74
-1
lines changed

front-controller/src/main/java/com/iluwatar/App.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* The Front Controller is a presentation tier pattern. Essentially it defines a
6+
* controller that handles all requests for a web site.
7+
*
8+
* The Front Controller pattern consolidates request handling through a single handler
9+
* object (FrontController). This object can carry out the common the behavior such as
10+
* authorization, request logging and routing requests to corresponding views.
11+
*
12+
* Typically the requests are mapped to command objects (Command) which then display
13+
* the correct view (View).
14+
*
15+
* In this example we have implemented two views: ArcherView and CatapultView. These
16+
* are displayed by sending correct request to the FrontController object. For example,
17+
* the ArcherView gets displayed when FrontController receives request "Archer". When
18+
* the request is unknown, we display the error view (ErrorView).
19+
*
20+
*/
321
public class App {
422

523
public static void main(String[] args) {

front-controller/src/main/java/com/iluwatar/ArcherCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Command for archers.
6+
*
7+
*/
38
public class ArcherCommand implements Command {
49

510
@Override

front-controller/src/main/java/com/iluwatar/ArcherView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* View for archers.
6+
*
7+
*/
38
public class ArcherView implements View {
49

510
@Override

front-controller/src/main/java/com/iluwatar/CatapultCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Command for catapults.
6+
*
7+
*/
38
public class CatapultCommand implements Command {
49

510
@Override

front-controller/src/main/java/com/iluwatar/CatapultView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* View for catapults.
6+
*
7+
*/
38
public class CatapultView implements View {
49

510
@Override

front-controller/src/main/java/com/iluwatar/Command.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Commands are the intermediary between requests and views.
6+
*
7+
*/
38
public interface Command {
49

510
void process();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar;
2+
3+
/**
4+
*
5+
* View for errors.
6+
*
7+
*/
8+
public class ErrorView implements View {
9+
10+
@Override
11+
public void display() {
12+
System.out.println("Error 500");
13+
}
14+
}

front-controller/src/main/java/com/iluwatar/FrontController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* FrontController is the handler class that takes in all the requests and
6+
* renders the correct response.
7+
*
8+
*/
39
public class FrontController {
410

511
public void handleRequest(String request) {
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Default command in case the mapping is not successful.
6+
*
7+
*/
38
public class UnknownCommand implements Command {
49

510
@Override
611
public void process() {
7-
System.out.println("Error 500");
12+
new ErrorView().display();
813
}
914
}

front-controller/src/main/java/com/iluwatar/View.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Views are the representations rendered for the user.
6+
*
7+
*/
38
public interface View {
49

510
void display();

0 commit comments

Comments
 (0)