forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMVCLesson.java
More file actions
54 lines (47 loc) · 1.03 KB
/
Copy pathMVCLesson.java
File metadata and controls
54 lines (47 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package patterns.web;
public class MVCLesson {
public static void main(String[] args) {
Controller controller = new Controller();
controller.execute();
}
}
class Controller {
DBLayer dbLayer = new DBLayerImpl();
View view = new ViewImpl();
void execute() {
Student model = dbLayer.getModel();
view.print(model);
}
}
interface View {
void print(Student model);
}
class ViewImpl implements View {
public void print(Student model) {
System.out.println("name: " + model.getName() + " age: " + model.getAge());
}
}
interface DBLayer {
Student getModel();
}
class DBLayerImpl implements DBLayer {
public Student getModel() {
return new Student();
}
}
class Student {
String name = "Max";
int age = 20;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}