Speaking of the Class Designer

As I pointed out in my last post, VS2005 includes a Class Designer that those familiar with the UML class model should feel right at home in. By happy coincidence, I found out today the Class Designer team is blogging. Additionally, two of the Class Designer team members – Ramesh and Rakesh - are blogging on their own. Apparently, the team blog will feature a new post every Thursday. This week’s post features an overview of the v1 Class Designer goals. Subscribed.

Putting a Square Peg Model in a Round Hole Tool

Robert Bauman left the following comment on my Separated at Birth post?

The nice thing about using a general purpose modeler is that you can house all of your requirements, use cases, etc. in the same model. Rational provides the 4+1 view, Sparx Systems Enterprise Architect provides several views out of the box that you can easily navigate around… It means that everyone is working off of the same set of rules.

As soon as you start putting those rules into Visual Studio, they change and deviate from the model. It’s true that the AndroMDA does require you to remember to use certain stereotypes, but that’s all part of the game anyhow.

That’s like saying, “well, the GoF patterns are nice, but then you have to remember what it means to have an Observer pattern”. Furthermore, UML tools let you customize the list of stereotypes that show in the dropdown, and even the picture that should be associated with those stereotypes. Why mess with some other modeling standard when you can do it all with a proper UML tool

The point I was making is that when you start using the class model to design something other than classes, you’re using a domain specific language – even if you’re using a general purpose modeling tool.  Take a look at this example from the AndroMDA website. Their example reads:

You tag a CustomerService class with a <<Service>> stereotype. AndroMDA sees this stereotype, looks into its internal dictionary of available code generation components (called “cartridges”) and finds the EJB cartridge. In the EJB cartridge, two templates correspond to the <<Service>> stereotype: SessionBean.vsl and SessionBeanImpl.vsl. AndroMDA uses the internal representation of CustomerService loaded from the model, calls the processing engine twice, and two output files are generated: CustomerServiceBean.java and CustomerServiceBeanImpl.java.

In this example, classes with the <<Service>> stereotype actually generate two code classes – the Bean and the BeanImpl. But if we were using the class diagram as it was intended, wouldn’t there be a one-to-one mapping between a class in the model and a class in the code? As soon as you break that one-to-one mapping, you’re no longer modeling classes. A <<Service>> is something at a higher level of abstraction than a class – otherwise it wouldn’t take two classes to implement it.

BTW, I’m not saying that there is anything wrong with this approach at all! I’m just pointing out the similarities between an approach that many people are using to achieve practical results with UML today and what you can do with the modeling tools that Microsoft is building.

The key difference comes down to tools. Yes, you can use the class diagram and stereotypes to model stuff at a higher level of abstraction like Services and Entities. But putting a square peg in a round hole like that has problems. Since you’re not using the tools as they were designed, you have to manually enforce rules that the tool doesn’t know about. Sure, you can add some semantics via stereotypes, but you can’t take anything away. How easy is it to build a valid class model that isn’t a valid service model? Pretty easy. For example, do services support inheritance? Classes do. My EJB is a little rusty, but I don’t think beans do. It certainly doesn’t make sense for a service to inherit from an entity or vis-versa. Yet, the class modeler will happily let you do this, even though it makes no sense in the domain you’re actually trying to model.

The value of domain specific languages is that have a tool that is specifically designed to model the domain you’re working in. If you’re designing classes, of course you’d want to use a class model. We have a great one coming in VS2005. But if you’re designing services or entities or page flows or whatever else, why wouldn’t you want a tool that’s specific to the problem at hand?

MDA And Software Factories – Separated At Birth?

Tonight I went to the monthly meeting of the local chapter of IASA. I should have also blogged this before the meeting, but I forgot. Sorry about that if you live near the Microsoft campus and wanted to go. Next meeting is on 3/30, so mark your calendars.

Anyway, tonight’s topic was an MDA workshop featuring AndroMDA. AndroMDA is an open source tool for generating primarily J2EE code for *nix boxes using UML and MDA. (To be fair, the speaker – local chapter president Chris Sterling – demonstrated generating C# code as well. Of course, he ran it under Mono on a Linux box.) This provided a great launching point for a general modeling discussion that helped me get a few things straight in my head. Typically, the UML vs. DSL discussion turns religious pretty quickly. However, I believe that people – like those a the meeting tonight – who are achieving practical success with MDA in the real world are doing so by using a Software Factories style approach.

First off, if you look at how most people use UML for MDA, the class diagram appears to be the most dominant model used. When I say “UML for MDA”, what I mean is people using UML as a blueprint or as a programming language. While UML has 12 different model types, class diagrams make up the bulk of the modeling effort. (The bulk of AndroMDA code generation works off the UML class diagram, though the BPM4Struts cartridge uses Use Case & State models as well) The other 11 diagrams are primarily used for sketching purposes. That means you’re only blueprinting the structural aspect of your system – which in turn means that all the system’s behavior has to be implemented by hand. Now, this is not to say that factories suggests you should only model the structural aspect of your system. However, I think this indicates that most pragmatic users have realized MDA doesn’t live up to the hype.

Secondly, the class diagram that are used have to be heavily adorned with custom metadata – typically in the form of stereotypes – in order to be useful for code generation (i.e. blueprint) purposes. AndroMDA has a set of “cartridges” (essentially, target code generators) such as EJB, Hibernate and POJOs. Each of these cartridges has a supported set of stereotypes. While there is some overlap (for example, EJB and Hibernate cartridges both define the Entity stereotype). These stereotypes assign brand new semantics to the elements being modeled. In short, they turn the the generic class modeler into a domain specific modeler!

It appears to me that the pragmatic MDA crowd is using the class diagram as a generic “ball and stick” editor. Model elements that aren’t needed are ignored and elements that are needed are added via stereotypes. For example, you can use a class diagram to model a database. Certain elements of the model are ignored (Can a column have protected visibility? Can one table inherit from another?) while other elements specific to the domain being modeled are added (primary and foreign keys, indexes, etc). The problem with this approach is that all of the knowledge of how to build a valid model is in the user’s head, rather than the tool. Typically, that means a lot of training as well as a lot of in depth understanding of the framework underlying the model in order to capture the right amount of information. Since all that domain specific information is trapped in the users head, they have to do a ton of menial drudge work. It’s different drudge work from things like writing tons of data access code, but it’s drudgery nonetheless.

If you’re going to need a tool specifically designed for your problem domain, why use a generic tool and a bunch of handwritten rules, when you can codify those rules into a domain specific language of your own? (I mean, other than the obvious “because the DSL Toolkit hasn’t shipped yet”)

Speaking of Steve

BTW, if you haven’t seen Steve’s entry on Isomorphism, go read it right now. He nails this whole services as contracts vs. services as code debate right on the head. The spot on nature of this post reminds me when he nailed the modeling problem on the head – another must read post if you haven’t already.

Thoughts on Factories

Last week, I had a great discussion with the Product Unit Manager (or PUM) of VSTA. She wanted my perspective on a few things related to Software Factories and I figured I’d share some of them here.

First off, while I appreciate the vision of factories, I’m also focused on the short term gains of automating software construction. Today, most of that automation is in terms of code generation. For example, John asked the other day if I thought Yacc is a software factory. It certainly is a domain specific language! However, I’m not sure I’d go so far as to say it’s a factory. But on the other hand, I’m not sure it matters that much if it’s a factory or not. When the other John on my team blogged his thoughts on SOA, he included one I wrote: “Eventually we’ll stop talking about SOA and go back to talking about Architecture”. I feel sort of the same way about factories. As long as we’re talking about it as if it is something different from what we’re already doing, we’re not there yet. But if we keep taking steps in the right direction, eventually we’ll get to the point where the process of building software doesn’t look the way it does today. Sorta the same way that building software today doesn’t look like it did pre-.NET, pre-VB, pre-Windows or pre-C++ (I could keep going, but I think you get the point). That’s the thing about visions, you never really get there, it just provides a way to keep you going in the right direction.

Secondly, I think that one aspect of Software Factories that at least I haven’t focused on is reusable frameworks. The book is called “Software Factories: Assembling Applications with Patterns, Models, Frameworks, and Tools” but I think the focus has been mostly on models and tools. This is partially because of the whole DSL vs. UML flack (quick side note – how about we have both?) and partially because the DSL toolkit is the first factory-esque thing that we’re shipping. However, DSLs big value, IMO, is to automate the construction of applications built on top of well designed reusable frameworks. For example, the OOPSLA keynote demo was a DSL that would sit on top of a UI process framework such as the p&p UIP block. But if there is not a good framework, there’s little point in having a language. I’ve pointed out in the past that the big gap to cross for organizations to start using DSLs is the leap from building abstractions to building languages that automate that abstractions. However, that’s not really true. The really big gap is the leap from building one-off abstractions to building reusable frameworks of abstractions. Once you have the reusable framework, building the DSL is an easier step IMO.

Even though I didn’t figure out the framework / factory connection until last week, it must have been there in the back of my mind when I was working on the ARC track for TechEd. We’re having a session on “Design Considerations for Enterprise Application Frameworks” with Steve Maine as the speaker.