1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Using Design Patterns in Java Projects

MVC

Contents

keyboard_tab
Design Patterns
1
Design Patterns
PREVIEW2m 26s
2
Singleton Pattern
PREVIEW3m 13s
9
Decorator
7m 48s
10
Flyweight
9m 20s
11
Proxy
7m 36s
12
Facade
6m 5s
14
Command
11m 44s
15
Iterator
8m 24s
16
Visitor
9m 4s
17
Mediator
11m 38s
18
Memento
9m 48s
19
Observer
10m 40s
20
Strategy
8m 27s
21
State
10m 27s
22
Template
7m 56s
23
MVC
10m 27s
26
DAO
10m 27s
27

The course is part of this learning path

Start course
Overview
Difficulty
Intermediate
Duration
4h 56m
Students
22
Ratings
5/5
starstarstarstarstar
Description

This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.

Learning Objectives

  • Understand what design patterns are
  • Learn about the myriad of design patterns that you can use in your projects

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.

Prerequisites

Basic knowledge of Java programming.

 

Transcript

Hello dear friends. In this video, we will examine the MVC pattern. Let's begin. Design patterns concentrate more on the tactical aspects required to solve a low-level problem. But in big projects, you also need an architectural pattern. Architectural patterns focus on the strategic high-level composite structure of a solution. They are usually implemented with multiple design patterns. They define the role of each subsystem in the overall solution. Now, the MVC is an architectural pattern. Model-View-Controller, MVC pattern, is an architectural pattern found in many places including the Java Foundation Classes API. MVC separates presentation management from core application logic. Useful in applications where the user interface might frequently change and MVC can be adapted to web applications. The Model-View-Controller is a well-known design pattern in the web development field. It specifies that a program or application shall consist of data model, presentation information, and control information.

The MVC pattern needs all these components to be separated as different objects. The model designs based on the MVC architecture follow MVC design pattern. The application logic is separated from the user interface while designing the software using model designs. The MVC pattern architecture consists of three layers. The model contains only the pure application data. It contains no logic describing how to present the data to the user. The view presents the model's data to the user. The view knows how to access the model's data, but it does not know what this data means or what the user can do to manipulate it. The controller exists between the view and the model. It listens to events triggered by the view and executes the appropriate reaction to these events. In most cases, the reaction is to call a method on the model. Since the view and the model are connected through a notification mechanism, the result of this action is then automatically reflected in the view.

In Java programming, the model contains the simple Java classes. The view is used to display the data and the controller contains the servlets. Let's look at the advantages of MVC architecture. MVC has the feature of scalability that in turn helps the growth of application. The components are easy to maintain because there is less dependency. A model can be reused by multiple views that provides reusability of code. The developers can work with the three layers as model, view, and controller simultaneously. Using MVC, the application becomes more understandable. Using MVC, each layer is maintained separately. Therefore, we do not require to deal with massive code. The extending and testing of applications is easier. The Model-View-Controller, MVC design pattern, specifies that an application consists of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects. MVC is more of an architectural pattern, but not for a complete application. MVC mostly relates to the UI or interaction layer of an application. You're still going to need a business logic layer. Maybe some service layer and a data access layer.

That's all I have for now. Let's implement MVC to a small project. I want to create a small project for employee details. I'll define an employee before changing the values of that employee. Let's begin. First, we will start with model. 'Class', 'Employee'. This will be an encapsulated class. So, we will define our properties. 'Name'. 'Job'. And employee 'registration' number. Generate getters and setters. Now, we need a view. 'Class', 'EmployeeView'. In this class, we will show employees' information to the users. Now, we will create our controller. First, in controller, we have to define model and view. In the constructor, we will get these as parameters. Now, in controller, we also need getters and setters for the employee properties. Let's define an update method also. Done. Now, our structure is ready. Let's use. Let's define a method to fill model with employees' information. In a real project, this will be our database operation. But now, we will set items manually. First, create an instance from Employee model. Now, set values. '("Charles Dickens")'. '("Author")'. Number is '12'. 'Return' model. Now, we will call this method. Let's define a view. Now, we need controller with view and model. When we call the update view model, we can see all information about Charles Dickens. Let's set new values to the model. Update again.

Done. When we run the project, we will see all information of Charles Dickens and John Verdon. Let's try. Look, Charles registration is 12 and John is 14. Great. We have now finished looking at the MVC model. In the next video, we will start examining the J2EE patterns. See you in the next video.

 

About the Author
Students
433
Courses
47
Learning Paths
2

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics