Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC and Java in comparison with more strict MVC languages

I've been told Java is not the greatest pick to follow an MVC architecture. I believe I've seen some Java framework solutions to ease this roadbump. However, I a bit confused on why this is. More specifically, why Java's attempt at MVC is often mocked as a "wannabe" approach. I come from a ObjC background (w/ Cocoa of course) and would love to hear from the seasoned programmers about why MVC with Java is said to fall short.

Appreciate it!

like image 560
Rev316 Avatar asked Mar 21 '09 02:03

Rev316


People also ask

Which programming language is used for MVC?

The MVC pattern is widely used in program development with programming languages such as Java, Smalltalk, C, and C++.

What is better than MVC?

MVVM is better than MVC/MVP because of its unidirectional data and dependency flow. Dependency is one way, thus it is a lot easier to decouple it when we need to. It is also easier for testing. All my projects(written in Kotlin for Android app) are based on MVVM.

What is MVC framework in Java?

The Model-View-Controller (MVC) is a well-known design pattern in the web development field. It is way to organize our code. It specifies that a program or application shall consist of data model, presentation information and control information.

Is MVC a technology or language?

Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of information from the ways information is presented to and accepted from the user.


2 Answers

You say you come from a Cocoa background so I'm assuming you're not talking about web-framework MVC. Most webframeworks that say they do MVC are actually using a different pattern called Front Controller, it's a bit of a different story from normal MVC because you need quite a lot of plumbing to make that work. Hence all the MVC frameworks in the web-world, originally MVC was a pattern for window-based applications. For these applications you can make MVC work without needing a framework.

MVC is a pattern that can be implemented in any object oriented language. There's no reason why you can't do it in Java. The only reason I can think of why people would call MVC on Java a "wannabe" approach is that the UI libraries on Java like Swing do not actually require you to do MVC. They just give you the tools to implement a View. You'll have to create controller and model classes yourself.

Discussions about what 'real MVC' is are usually not really constructive anyway. MVC is a pattern developed for smaltalk about 30 years ago. None of the implementations that are used now are exactly the same anymore, many implementations are improvements. You've got different flavours called MVP, MVVM, Document-View etc. And they are all usefull in some cases. The important thing to take away from this is that its a good idea to separate your UI logic from your application logic. Java can do this and so can most other languages. People claiming otherwise are probably just afraid to look outside the language they're comfortable with.

like image 95
Mendelt Avatar answered Oct 05 '22 22:10

Mendelt


At it's roots, MVC is a programming model. I consider it to be platform and language agnostic. I used to follow the MVC principles in C++, so I'm not sure why any language would be considered as "falling short" with regard to following these principles. Admittedly, I'm a .NET person these days, but I think with a little effort they could be applied to Java. See Java Model-View Controller for some ideas.

like image 41
billb Avatar answered Oct 05 '22 23:10

billb