GUI: Decoupled view and design patterns for RIA - user-interface

I made some GUI desktop applications on my first years of development, but my experience and practice have changed, so now I'd like to retake this subject with better knowledge.
Most of my experience has been web since then.
I've been reading about GUI Architectures, and several related questions here on S.O.. I know I'm still not in the "architect" level of knowledge from Design patterns and such, as to start building a great GUI App from scratch
I'm trying to figure out how to design an app with a GUI, using good design practices for the architecture. I'm focusing on MVC architectures, with RIAs (Flex, Java FX, you choose), thinking of keeping the GUI as decoupled as possible from the domain. This has brought me some trouble...
I've been having a hard time relating an MVC architecture such as SpringMVC with a GUI, which could also implement its own MVC. Most of what I've read are high level concepts, but I can't seem to be able to translate this into code.
"Where do I create the view?", "How do you hook the controller with the model and the view?", etc. These are some of the questions I keep asking myself after some reading and studying.
I'm probably kind of lost, and quite entangled as to where to start, so any help is appreciated.
Are there any guides/tutorials/documentation you can recommend to start on this subject? I should probably start with the RIA/GUI basics, and then specialize on the technology I'll use.

You didn't specify which language you prefer, but here are some practical guides for Java:
Java SE Application Design With MVC:
http://www.oracle.com/technetwork/articles/javase/mvc-136693.html
Model-View-Controller (MVC) Structure
http://leepoint.net/notes-java/GUI/structure/40mvc.html
Also, for specifically SpringMVC, here are some practical guides:
http://maestric.com/doc/java/spring
http://www.zabada.com/tutorials/spring-mvc-basics.php

Related

Tools for documenting MVC web application

I'm making a web application that is quite a bit more complicated than others I've produced in the past. I think before I go much further I should try and get down a plan for the application as I currently have it.
I recently took a course in UML, but that doesn't seem particularly appropriate here - as while I'm using an object-oriented framework it is really the relationships between the Models, Controllers, Actions, Views and URL mappings I'm looking to document.
So my question is - Are there any software design applications out there that are particularly useful for documenting the structure/functionality of an MVC application?
On the basis of this I'd be hoping to write a testing plan.
Documentation is not for the creation of "testing plan" (whatever what means to you). If you want to test your application, you should have been writing unittests all along.
This sort of documentation is meant to alleviate the confusion in larges-scale applications. And the use of UML would be appropriate in this case, though there is no rule, that states you have to use all diagrams. But in your situation class or component diagram might be quite useful, with some sequence diagrams to illustrate more confusing parts of the application.
Also some ER diagram might help, if you have a complicated DB structure.

MVVM, Unity, Prism, MEF, Caliburn - What should I use?

Please help - I'm getting lost!
I'm writing a small desktop application which has some controls and some screen. This should later be integrated with a small web site, also having some screens. The idea is to let the user edit videos and select images, and then share their results with her friends.
The desktop app is using C# WPF, the web site - ASP.Net MVC.
I read that growing the application past a few screens would be easier using MVVM. So I started searching and discovered Caliburn.Micro and MVVM.Light. I have downloaded some tutorials but, just as I was getting ready to deep-dive into the material, I found here on S.O. that there's also Prism, MEF, Unity, ReactiveUI - This is becoming too much!
I'm terrible at learning new things - It's taking me ages to study WPF and ASP.Net MVC. I don't want to study lots of new material only to find out later that it's not relevant. And I don't have an architect to instruct me.
So my question is: Could you put these frameworks and technologies in perspective, and suggest which I should focus on studying and using (esp. what can be later used with Windows 8)?
If you want to build an MVVM application (which you probably do for various advantages), then you want an MVVM framework.
I would recommend Caliburn.Micro, as it is straightforward to implement following the examples on the Caliburn.Micro documentation page. It also has a very compelling convention over configuration mechanism, and uses an Actions system to invoking verbs (methods) on your view models from the view. This is more powerful than any other mechanism I've seen.
Prism is quite a heavyweight framework which includes elements of MVVM design to help the implementation, as well as being particularly tailored towards building composite applications (applications that are built up of decoupled components within a hosting shell).
MEF is useful for these types of applications that need to discover plugins or extensions to the application (even after the application has bootstrapped), and can be used alongside an MVVM framework such as Caliburn.Micro. MEF can also be used for implementing inversion of control, but doesn't provide some of the core features found in other inversion of control containers, so you may decide to only use it to implement plugin functionality.
Unity is an IoC container, and would be used to implement dependency injection for your general application infrastructure. There are lots of IoC containers in the .NET space though, some of which offer either improved performance, additional features, or a more friendly API.
I don't know about ReactiveUI as I haven't used it.
If you're talking about maximising code reuse for a move to WinRT, then MVVM is a great choice.
PRISM already include MEF and MVVM logic :)
Ok little bit of explanation here:
MVVM stand for logic in your application. Actually clever way of decoupling of View, View-Model and Model. Don't know any best (?) framework to do it - you could check Catel if you want or MVVM Light but it just a tons of code from someone who understand the MVVM logic and just make it easy to implement it. You could actually try to write your own MVVM framework and see that 'there's no secret ingredient' - just the same repeating code and same classes, etc... Actually you don't need any MVVM framework to implement MVVM.
Once you learn and write MVVM you immediately run into question - How I NUnit test it in decoupling way (this is not trivial problem in Silverlight for example) - so here all IOC/Inject framework come into play. For example MEF. Consider following example to understand a big picture about Inject framework:
Project 'Shared', written in 'least delimiter' (for example Portable Library)
public interface IAmSharedInterface
{
string SayHello();
}
Project 'Main', reference only 'Shared' project
public class IAmMainClass
{
[ImportingConstructor]
public IAmMainClass(IAmSharedInterface SharedInterface)
{
SharedInterface.SayHello();
}
}
Project 'Implementor', reference only 'Shared' project
[Export(IAmSharedInterface)]
public class IAmImplementor: IAmSharedInterface
{
public string SayHello()
{
return "Hello from implementator class to whoever using it";
}
}
You see - there's no direct reference between 'Main' and 'Implementator' projects - all 'magic' happens in MEF/Unity build/resolve process. So you could easily run NUnit test on Main without using 'Implementor' project and 'Implementor' with 'Main'. There's also a scenario where other project could implement and export 'IAmSharedInterface' specially for testing purposes.
So back to PRISM - it have all (!) this. I know it's not easy framework to understand right away and it doesn't suitable for simple 'Hello World' programs but once you learn it - there's no way back. It just glue all the parts together and give you big degree of freedom in using whatever moq framework you want (for example Rhino).
Prism developing in Microsoft so (I hope) it will be supported not just in Windows 8 but in Windows 9 and in all future versions.
Whatever you asked it's all inside: MVVM, Inject, decouple/plug-ins, easy to read and test
To save adding to the detailed information above, I'll attempt to make life easy for you.
1) For now, forget about IOC / Dependency Injection / Plugin architecture. You say you're creating a simple app, so forget about this for now. Keep your code tidy and you can implement this later if necessary (it's good stuff).
2) Out of the frameworks you've listed I would suggest Caliburn.Micro. It's relatively straight-forward and lightweight. It wouldn't take you long to get up and running.
3) Create your model in a separate assembly which you can use for both your windows app and your MVC website.
Keep it simple and don't get bogged down with all the technologies.
This answer reproduces some abridged chunks of Rockford Lhotka's Blog article "Using the MVVM pattern requires a framework" which was cited in another answer.
It is sort of a meta-answer to this question (though it does contain a specific recommendation), but it seemed very useful to explain the role of a framework in MVVM in the first place.
There are three fairly
popular presentation layer design patterns that I collectively call
the “M” patterns: MVC, MVP, and MVVM. This is because they all have an
“M” standing for “Model”, plus some other constructs.
The thing with all of these “M” patterns is that for typical
developers the patterns are useless without a framework. Using the
patterns without a framework almost always leads to confusion,
complication, high costs, frustration, and ultimately despair.
These are just patterns after all, not implementations. And they are
big, complex patterns that include quite a few concepts that must work
together correctly to enable success.
...
Trying to do something like MVVM without a framework is a huge amount
of work. Tons of duplicate code, reinventing the wheel, and retraining
people to think differently.
At least with a framework you avoid the duplicate code and hopefully
don’t have to reinvent the wheel – allowing you to focus on retraining
people. The retraining part is generally unavoidable, but a framework
provides plumbing code and structure, making the process easier.
You might ask yourself why the MVC pattern only became popular in
ASP.NET a few short years ago...
Strangely, MVC only started to become mainstream in the Microsoft
world when ASP.NET MVC showed up. This is a comprehensive framework
with tooling integrated into Visual Studio. As a result. typical
developers can just build models, views, and controllers. Prior to
that point they also had to build everything the MVC framework does –
which is a lot of code. And not just a lot of code, but code that has
absolutely nothing to do with business value, and only relates to
implementation of the pattern itself.
...
Typical developers really do want to focus on building models, views,
and viewmodels. They don’t want to have to build weak reference based
event routers, navigation models, view abstractions, and all the other
things a framework must do.
...
In the meantime, Caliburn Micro appears to be the best MVVM framework
out there – certainly the most widely used [as of 2012]...
(Text copied inline for preservation reasons.)

Looking for great examples of MVC frameworks

I've recently heavily gotten into Javascript programming. Currently I'm building a 'Fat client' powered by a PHP-based REST webservice.
This is going pretty well, but I want to learn more.. become an expert if you will.
My background is mostly MVC in PHP, so building true real-time GUI applications based on the MVC model is pretty new. MVC exists in PHP, but it's quite different. In javascript, because it's 'live' there's a much stronger emphasis for message-passing and events.
I'm learning based on the YUI3 and Backbone.js frameworks. I believe this is a solid foundation. I do feel though that, in order to become better I should try to learn from other (non-javascript) MVC systems.
I have some (very distant) memories of playing around with both Visual Basic and Delphi (6 and 7). Even though I'm sure these have solid frameworks behind them, there must be other frameworks out there that are great to learn from. I'd love to see a solid, non-javascript, lightweight framework or language I can learn from and borrow concepts from.
So my real question is: in the great history of GUI programming, what are some good examples of articles, books, or codebases I can read to strengthen my understanding of MVC, what has worked in the past and what has not, and how to create an elegant but powerful design.
Chapter 11 of Beautiful Architecture is about the MVC architecture in Emacs. Even if Emacs is not your cup of tea, it's still an interesting case study. An application that has been in active use and development for 24 years must be doing something right.
It cost a bit of money but the DoFactory stuff is great, I used it. Show how to implement enterprise level applications with MVC and a few other frameworks.
http://www.dofactory.com/products/products.aspx

Required language, tools and approach for a scalable web application like twitter

Incase if you are to develop twitter today what language, tools and approach will one take. How will he start from the very frugal configuration and gradually scale to the levels twitter has reached today. Incase if you can provide direct responses like (PHP+ Apache+ memchached+ MySQL) or (JSP+TomCat/Glassfish+ MySQL / other db) etc.
The criteria is an architecture which scales easily without much engineering and the right language so that one doesnt need to rethink his decision once the same is in place.
(As far as I know, Twitter is RoR, Linked in is Java and Digg in Php. So not looking for just random thoughts :) ) Do support why do you think your option should suffice.
Thanks
As you already say it, there are several applications that shows that several technologies are able to scale. Fortunately for them.
I think you should not focus only on "is this technology the best for scaling". But on the two following points :
Do you have skills in that technology ?
Is that technology adapted (by it's philosophy) to that application ?
Scaling is a thing. But if you can't develop your application with the "killer" technology because you don't understand it, it's anyway useless.
I recommend looking at the High Scalability website. You can build a scalable web app in virtually any language, but it's not just a matter of using the right technology and then plugging it in. You have to know what you're doing, no matter what technology you use!
Twitter was developed using the framework Ruby on Rails (ROR), and that seems to be a good choice. Ruby on rails is database agnostic (supports most databases), very scalable and very good for developing web applications quickly.
Cake is a popular alternative for PHP I haven't used Cake but hear it is very similar. The alternative to these open source alternatives would be a full blow enterprise environment like the microsoft .NET frameweork.

Should new web applications follow the MVC or MVP pattern? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Note that I am not asking which to choose (MVC or MVP), but rather if one of the two should be used for a web application.
I realize that it might be too much work to convert an older application from its current design to a MVC or MVP pattern. However, what about for a new app? It appears these are the most popular architecture patterns, so should one of these be chosen? If not, what other patterns are there?
If you are not familiar with MVC and/or MVP, a good question to check out is "What are MVP and MVC and what is the difference?". It has many good answers, including links to various websites that break down each one.
MVP / MVC works well in web applications because the HTTP verb + URL combination is a very good way to determine which action to take. There are reasons not to use it, such as if your team has a lot of experience with another framework, but I would generally recommend an MVP / MVC framework. Your application will be finished quicker with higher quality.
Both are great options.
I'd go for MVC as it has a wider adoptions and its easier to understand and use to frontend (HTML / CSS) developers.
Also, given the number of frameworks adopting the MVC pattern, chanches are talking with your coworkers in MVC you will talk a well knew language.
Your question was "should I use one of these design patterns".
I'd have to say that that really depends on the scope of your project. On a very large project that has interdependencies with other systems in a large organization with a large budget, I'd say they are definitely worth considering.
I think these patterns are often over-used on smaller projects where they may add unneeded complexity and cost.
The main point of loose-coupling, is so that you can change your DB or UI at a later time, or re-use business logic. Often times, this never happens. You have to realize that either of these patterns will take longer to implement and complicate the code quite a bit. So, I strongly suggest really thinking this over and weighing your options. You can often deliver a better solution faster by using a very simple architecture that gets the job done and reduces complexity!
I have posted the following answer for another question, though it may be more appropriate here.
MVC is good for plain server side scripting. In MVC developers always try to keep the controller very lean. Mainly controller is for just selecting the appropriate model and reflect on the view. But in today's web applications the View part has radically changed and became complex enough to produce a big, fat and messy controller. So now we need a new place to put the user interface's complex control logic. Here the P of MVP comes in that is the presenter. So presenters are responsible for controlling the logic for a particular user interface component. Don't worry the controller is still here, named as Application Controller. Which ultimately responsible for switching between comparatively larger application components. So MVP can also be said MVPC(!!). BTW this was my way of understanding MVP and obviously not any ground rule.
So I am already tend to MVP for complex web apps.
It depends on the framework you're using. Just use what it supports.
Most web frameworks I've seen use the front controller pattern and call it MVC or MVP.
I think that you should. They are harder to implement, especially in MS world because they did everything to push Web Forms and make building web applications more easily.
Using them you are programming straightforward and you feel like you've done a lot of work. But they are slower and harder to maintain after your site gets bigger.
Using MVC and MVP allows you to separate model(basic classes that represent domain you are working with), controller and views. The best thing about that is that you can reuse your model in other applications like mobile applications or windows apps. They then have more in common than just a database so you have to write less code. You just have to write controllers and views.
I am new to this but I see benefits because when I had to change something on one place something else crashed elsewhere(so you also have to get loose coupling into account and writing unit tests). Writing tests is impossible in Web Forms.
However, if you are building application to represent a person or a company, where there is no business logic on the web, and you have to do it fast, Web Forms are good for it. And also for building prototypes so you can show what application will be able to do when finished.
I like both patterns. My best practice is to choose an pattern, that is always better then NO pattern.
I've developed many applications on both patterns, my personal feeling is that when you are an RAD developer and you are not so good with CSS & javascript(Mostly winforms developers who want's to create an webapp, no offense ;-) ) You should use the MVP pattern because this is very easy to use with the Web Application Projects.
But when you known allot of CSS & javascript then you should consider the ASP.NET MVC pattern.
I would prefer the MVC Pattern, just because the loose coupling. There is a clear seperation between model, view and controller and through the isolation it`s better suited for Test-Driven Development or just Unit-Testing.

Resources