Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to implement MVC for a java console app?

I want to practice MVC with java but at the first I want to create a simple console app and separate it into MVC I know I can separate MODEL from console(view + controller) but how can I separate view and controller in this situation?

like image 434
Seyed Vahid Hashemi Avatar asked Nov 19 '11 13:11

Seyed Vahid Hashemi


People also ask

Can MVC be used in Java?

Advantages of MVC Architecture in JavaAs components have a low dependency on each other, they are easy to maintain. A model can be reused by multiple views which provides reusability of code. Adoption of MVC makes an application more expressive and easy to understand. Extending and testing of the application becomes ...

How does MVC work in Java?

The Model View Controller (MVC) design pattern specifies that an application consist 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 complete application.

What is controller in MVC in Java?

MVC stands for Model View and Controller. It is a design pattern that separates the business logic, presentation logic and data. Controller acts as an interface between View and Model. Controller intercepts all the incoming requests. Model represents the state of the application i.e. data.

How can I learn MVC in Java?

Relational Database Design EssentialsMVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application's concerns. Model - Model represents an object or JAVA POJO carrying data. It can also have logic to update controller if its data changes.


2 Answers

Yes

The whole idea of MVC is that view doesn't matter. So, basically, you can build whatever you want application using MVC principles.

like image 50
Stan Kurilin Avatar answered Oct 18 '22 03:10

Stan Kurilin


Well you can mimic that behavior by having a class that handles user console input (controller) and another class that deals with rendering the model on the console output (view).

It's not really what MVC is for, but if you really want to do it...

Edit: Ok, I'm going to give you some concrete ideas about the controller. You know that in a GUI app, you have the so-called "message loop". You will need to mimic this in your console app. Try to start a parallel thread that receives console input in an infinite loop. When input is received, call a handler method from the controller class.

like image 3
Tudor Avatar answered Oct 18 '22 03:10

Tudor