MVC with Admin and User Views
This program demonstrates MVC with different views for admin and user.
Problem Statement
Write a Java program where Controller updates both AdminView and UserView.
Source Code
| 1 | class Model { |
| 2 | String data="Eduinq MVC Data"; |
| 3 | } |
| 4 | class AdminView { |
| 5 | void display(String data){ System.out.println("AdminView: "+data); } |
| 6 | } |
| 7 | class UserView { |
| 8 | void display(String data){ System.out.println("UserView: "+data); } |
| 9 | } |
| 10 | class Controller { |
| 11 | Model m; AdminView av; UserView uv; |
| 12 | Controller(Model m,AdminView av,UserView uv){ this.m=m; this.av=av; this.uv=uv; } |
| 13 | void updateViews(){ av.display(m.data); uv.display(m.data); } |
| 14 | } |
| 15 | public class MVCAdminUser { |
| 16 | public static void main(String[] args) { |
| 17 | System.out.println("Eduinq MVC Admin/User Views"); |
| 18 | Model m=new Model(); |
| 19 | AdminView av=new AdminView(); |
| 20 | UserView uv=new UserView(); |
| 21 | Controller c=new Controller(m,av,uv); |
| 22 | c.updateViews(); |
| 23 | } |
| 24 | } |
Program Output
Eduinq MVC Admin/User Views AdminView: Eduinq MVC Data UserView: Eduinq MVC Data
Explanation
Controller updates both Admin and User views. - Different views present same data in different contexts. - This models enterprise apps with multiple user interfaces. Conclusion: Shows MVC with multiple views for admin and user.