(Originally posted on http://mcory.wordpress.com/ on 10/18/07)
Got a few things I wanted to share today, and I don’t really have as much time to blabber on as much as I’d like, so here we go.
Model-View-Presenter Architecture
Ran into this article on CodeProject yesterday. Excellent article on setting up an MVP architecture for an ASP.NET site. Maybe not quite the best ever written, but it finally put the MVC/MVP arch into a different light for me — I actually almost understand it now.
Quick warning: it’s a long article. About 18 pages printed up. Good bathroom read; much too long to take in on a smoke break. Anyways…
I started trying to implement it in a little pet project this morning — a “Story Notebook” that I’ve been trying to make myself write for almost a year. Definitely put things in a different light, especially with unit testing/test-driven development and whatnot. Of course, I’m working on a desktop app and the article is for ASP.NET, but the concept isn’t platform dependant of course.
Here’s my understanding of the architecture; I’m probably wrong, and feel free to correct me if I am.
Model: your data object, your Person class or Employee or Widget or whatever. This is where your information gets stored, and it’s what works with (or, probably more appropriately, is worked on by) whatever data model you’re using (i.e. ADO.NET, XML Serialization, etc.).
View: a representation of your model for a given scenario, and if you can fit it into a control, all the better. You have a NewPersonView and an EditPersonView; perhaps you can get by with a single, all-encompassing PersonView, but it’s better to break it up if you can. Odds are this’ll work directly with your model in some fashion.
Presenter: from what I’ve gathered — and I’m probably wrong — this is mostly an externalized constructor for a View class. You have a NewPersonPresenter and an EditPersonPresenter. Now, from some additional reading, I’ve seen that this also works to bridge the View to the data access layer — you may have a NewPersonPresenter.SavePerson() method, for example. This is the main part I’m a little iffy on, and it — and the Controller concept from MVC — is what’s really kinda kept me out of the loop with this kind of architecture.
Seriously, if you have anything that might be able to clear this up at all, I’d really appreciate a link or a comment on this stuff.
Java in .NET
Something else I came across yesterday at work is IKVM. It’s really cool. Essentially, it’s a program that compiles Java JAR files into .NET IL code — you can use Java class libraries just as if they were a regular .NET assembly. I believe it also compiles Java source into .NET, but if not you can always just use the Java compiler to create a JAR and then convert it to .NET. It also has support for setting up access to .NET assemblies from Java I believe, but I’ll let you play around with it and find out.
HtmlUnit
This is why I found IKVM — HtmlUnit is a class library for Java that lets you programmatically play with web sites. My manager came across it trying to set up Fitness tests for our site, and the actual Fitness fixture he was using didn’t do exactly what we wanted. The fixture was Java driven, and we need something that either works exactly as we want (unlikely) or at least uses .NET so we can play with it as necessary.
Instead of giving up, we searched the internet for several seconds and stumbled across IKVM. After playing with it for about five minutes, we had a little console application, using HtmlUnit, that loaded up our site, logged in, and started playing with stuff.
Anyways…
Thought I’d point those out to you. HtmlUnit looks like something worth playing with — it’s definitely something that has promise, and I’m sure with a good ten or fifteen minutes of brainstorming you’ll be able to come up with a good set of possible uses. Hell, I’ve already looked into automatically scraping my WordPress.com stats from the admin section so I don’t have to hit refresh every five minutes.
Alright, Patti’s under the weather so I need to do the “get ready to go” stuff with the beagle today. Enjoy the links, and someone help on the MVP stuff if you can…
Posted by: mcory
Posts that may or may not be similar to the above:
- Project "Pre" Post-Mortem
- Humble Pie: Not Just For Breakfast Anymore
- OOD Principles I: Liskov Substitution Principle
- Unit Testing & Code Coverage
- Ground-Up ASP.Net Development I: At the…Well…Ground.
Categories: