Example of a simple JavaFX Application using MVC, DAO pattern and different DataSources (Oracle, MySQL, SQLite)
- Simple app to show how to implement:
- GUI using SceneBuilder
- Controller/Model Injectable
- DAO for database connection using different DataSource classes for the database vendors, like Oracle, MySQL and SQlite
- Strict separation between GUI and Model/DAO
is one of the most common pattern for structuring software. It allows a far-reaching separation of data model and its graphical representation. A clear, clear structuring, the associated ease of maintenance and the reusability of program parts are among the top objectives of a successful program design. The MVC pattern allows the architectural main parts of software to be kept separate. Three parts are to be distinguished:
It contains the work data of a program, user input, data read from databases, etc.
The (in a desktop program of the same graphical) representation of data, the user interface (GUI), etc. You will find in the source text neither data, nor parts of the business or program logic. For this purpose, it defines appropriate interfaces.
The mediating layer, which is responsible for the interaction between the presentation layer and the data. It is realized by an observer pattern that observes the data of the model. updated with the presentation layer. The controller must therefore have access to both the data and the presentation layer.
is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source.
This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system service or some kind of repository.
my.package
Application
my.package.model
Model
my.package.services
DAOService
DataSourceOracle
DataSourceMySQL
DataSourceSQLite
my.package.ui
MainController
Main.fxml
my.package.utils
ControllerFactory
ViewLoader
ModelInjectable (Interface)
DAOServiceInjectable (Interface)
ExceptionListener (Interface)