This project aims to provide an MVC Java framework for you to use in your projects. If you want to see an example there is a simple and complete example about a scheduler in example folder.
Briefly, MVC (Model View Controller) is a design pattern widely used in projects because it leaves the project structured in order to facilitate the identification of application modules, understand how it is structured, in addition to facilitating maintenance. It structures the project in three modules:
Name | Funcion |
---|---|
Models | Responsible for business logic |
View | Responsible for the visual part |
Controllers | Responsible for the behavior of the visual part |
This project is based on book Head First design patterns. Below are some illustrations from this book about how MVC works.
This project adopted the following naming pattern:
Type | Name |
---|---|
Controller | <ControllerName>Controller |
View | <ViewName>View |
Note: This is just an adopted standard; if you do not like it, you can use another one.
In src
folder is all what you need to apply this pattern in your project.
Models should implement Model interface. This interface is like an observable and has three methods that must be implemented: "attach", "detach" and "notifyViews".
Views should implement View interface. This interface just have one method that must be implemented: "update".
Controllers should extend Controller class. This class has one method that must be implemented: "run".
To execute the application just run Main class. It will execute HomeController (that will execute HomeView).
Name | Type | Description |
---|---|---|
Controller | Abstract class |
Contains the main frame of the application. All controllers must extend this |
Model | Interface |
Has behavior of a Observator. All model classes should implement this interface |
View | Interface |
Has behavior of a Observer. All view classes should implement this interface |
Name | Type | Description |
---|---|---|
HomeController | Class |
It will be responsible for HomeView behavior. |
Name | Type | Description |
---|---|---|
Model1 | Class |
Example model |
Name | Type | Description |
---|---|---|
HomeView | Class |
Responsible for the look of application's main screen |
The MVC structure is in src
folder. In it, there are three folders and one files.
Name | Type | Function |
---|---|---|
bin | Directory |
Binary files (.class files) |
example | Directory |
Example of a project using mvc |
media | Directory |
Visual information |
src | Directory |
MVC framework |
.classpath | File |
IDE generated file |
.project | File |
IDE generated file |
Name | Type | Function |
---|---|---|
assets | Directory |
Contains all application content files |
controllers | Directory |
Contains all application controller classes |
core | Directory |
Contains classes and interfaces essential for the functioning of the MVC structure |
models | Directory |
Contains all application model classes |
views | Directory |
Contains all application view classes |
Main.java | File |
Class responsible for starting the application |
To be clear how the framework works I made a small application that consists of a scheduler, being possible to create new events and see the ones already created. It is located in example folder.
- Freeman, Eric, Elisabeth Robson, Kathy Sierra, and Bert Bates. 2004. Head First design patterns. Sebastopol, CA: O'Reilly.