
I have been searching since day one for an architecture that can make designing, extending and maintaining a complex FileMaker system easier. I have yet to find one. Sometimes I think FileMaker is too flexible. There are too many easy ways to do things that will absolutely cause you myriads of grief later. I have tried several times to develop my own frameworks, but they always left me feeling like it was too much work.
I have been talking over some new ideas about this problem with Ernest Koe of the Proof Group. It appears that his team of FM bright spots has reached a similar set of conclusions about how to apply some order to a complex FileMaker system. I hope that this series of posts will help to flesh out some of the ideas we have been kicking around.
The one architecture that gets discussed a lot is the "Separation Model". I have been a proponent of this model in the past. I have used it many times. I started working with it way back in the FM5 days after seeing Colleen Hamersely present on it at DevCon. The advent of FileMaker 7 made this model a bit easier to swallow, but after the newness wore off, I found myself with a bad aftertaste. There are just far too many compromises to make. A good framework should remove ambiguities. I find the separation model brings up more questions than it answers.
Using the Separation Model does have the effect of reducing, but in most cases not eliminating, the need to do data imports when upgrading systems. Certain kinds of projects can benefit from easier upgrades, but not all of them. Custom in-house solutions, for example, don't gain much from having easier upgrades. Couple this with the fact that you have to jump through all kinds of hoops, make lots of compromises, and weaken the readability of the code just to make this work. In my opinion, you quickly reach the point of diminishing returns.
One of the many problems with the Separation Model is the fact that it frowns on the use of FileMaker calculation fields. Calcs are one of the things that make FileMaker easier to use. In fact the more strictly you apply separation, the more you loose some FileMaker inherent strengths like calculation fields and record locking.
Recently, I have begun a serious journey into other programming languages. While doing so, I started hearing about a Design Pattern called Model, View, Controllerr (MVC). MVC separates code into three "areas." I am specifically NOT referring to them as three "layers."
The Model is a representation of the data, the View is what the user sees and interacts with, and the Controller mediates between the two. There is not a strict separation into layers. In fact, an MVC system is often made up a bunch of components that are also built using MVC.
Although at first blush the three areas look a lot like the Data, Logic, and Presentation layers of the Separation Model, they are different. Those differences have led me to start exploring MVC as viable Design Pattern for FileMaker.
What follows is my current approach to designing a FileMaker System using MVC, and why I think it is better than following the Separation Model. It is by no means complete, and will most likely change. In fact, I hope it does.
I am going to start by examining the Model (the "M" of MVC). MVC says that the "Model" is a representation of the data. In object oriented languages the model is often expressed as a class with properties and methods. In FileMaker terms the Model is expressed most often as TO's and Fields. Scripts and layouts can also belong to the Model, but I will leave that part for later.
What is the difference between calling something part of the Model or part of the Data Layer? First, the term Data Layer has a bunch of connotations attached to it that are difficult to fit into the FM world. Take normalization for example. There are many times that you simply must store data in more than one place for performance reasons. Pure separation says this is bad idea. Practicality says we have to do it. Another example is using calculated container fields to display something to the user. Pure separation says bad idea. FileMaker makes this super simple. It is one of its strengths.
Diving into the UI graphics issue a bit more, lets look at how the Model of MVC handles this problem. In an MVC paradigm the Controller might ask the model to "get" the UI graphic. The controller would then give the graphic to the View and say "display this graphic". In MVC, the UI graphic is just another attribute ( think FileMaker Field) of the Object (think FileMaker record). The fact that the Graphic lives in the same space the rest of the attributes is ok.
Getting very real about this one for a second, lets take the example of a customer record with a past due balance. The programmer decides that if the customer has a past due balance then they should get a big red Flag placed next to their name everywhere the name appears in the system.
Using the separation model, I have to put that logic onto every single layout in my system. I can do this by adding a bunch of TOs to my already complex relationship graph or doing some conditional formatting on each layout. Either way I have spread the logic out all over the place.
The MVC approach would view the big red flag as most likely belonging to the Model. The Model is the holder of all attributes and common functions that have to do with a particular entity ( ie record in a table). Therefore it makes perfect sense to simply create a calculation field that "gets" the correct graphic. The logic behind the displaying of the graphic resides in one place, the Model.
This resolved one of the long standing problems I had with using Separation. There are lots of types of Logic that BELONG to the data. They only make sense in the context of the data. They have no viable home anywhere else. Think of scenarios like "if this field value changes to 'A' make this other field 'A + 1'". Where else could that go, but tightly associated with the data?
MVC says, "Yup put that stuff where it belongs, in the Model."
This is not a perfect fit. We have yet to get into scripts and layouts, and how those almost have to play a role in the Model sometimes. There are other issues as well. But I do feel like MVC makes more sense as a Design Pattern then the Separation Model.
As you can probably guess Controllers are almost always expressed as FileMaker Scripts. And Views are almost always expressed as FileMaker layouts or parts of layouts. I hope to cover each of these in an other post in the very near future.
stay tuned
UPDATE:
Part 2 is here
Comments
MVC vs. The Separation Model (TSM)
I don't think that the argument should be MVC vs. TSM, because I don't view them as being mutually exclusive. Since there isn't a formal standard for TSM, what we are left with is a general design philosophy with elements that are more or less mandatory, and others which are optional to varying degrees. For instance, I've never felt that strict TSM frowned on calculations fields (although I'm sure others have). What you are proposing could work equally well with or without TSM.
- Dave
yes it did seem bit like MVC vs TSM
Looking back I can see how the post came across that way. I am certainly re-acting to TSM, because I find lacking and potentially misleading. I will still use at least two files for most complex systems, but mostly for the organizational level it provides. And I don't think I will stretch, bend or break perfectly reasonable FM techniques just to keep the data separate from the interface.
Thanks for your comments!
Skeptical but open
I've also been mulling how MVC (or other design patterns for that matter) map into FMP development. My initial gut reaction was the FMP stuff is so interconnected that implementations are very hard to segment cleanly. The advantage of MVC in class-oriented environments makes a clean separation of concerns and helps with the clutter that sometimes (usually?) happens in complex class-oriented projects. It then becomes pretty clear what part of MVC a particular class is supporting. FMP has radically different "objects" for us to work with that don't make encapsulation easy. For example, frequently I find myself using a mix of custom functions, conditional formatting, and the automatic data retrieval and display capabilities to create layouts that support a user interaction process. That mix is part data, part view and part controller. But I've yet to find a way to obtain an overview of my schema, Relationship Graph, scripts, functions etc. where I can tell at a glance what part of MVC any given object plays. I do find encapsulating complex logic into custom functions provides some advantages such as keeping all the related code in one place.
For example, while the schema columns contains the raw storage and the RG contains the natural joins required for a Model, even with judicious use of conditional formatting and variables, we end up with extra columns and TOs that support controller and view aspects. Similarly, on Layouts, which are largely View-oriented, we end up with conditional formatting and clever leveraging of built-in FMP characteristics that are more Model or Controller in their nature.
And with no way to obtain an overview of all these structural aspects or work with them cohesively in a MVC-like way, I'm not sure how the MVC paradigm can really be leveraged in a way that provides easier ways to support and extend our solutions.
I'm looking forward to this discussion.
Re: MVC Inspired: Part 1, The Model
Scary! This so much of the way I've been working MVC into my FileMaker developing. I have been using MVC on the web for a long time and it's a little easier there, but I digress...
I see Controller being the scripts and subscripts, but more for the "flow" and "navigation". Any 'get' or 'set' action surely is Modal as you are working directly with the data, even if these actions have to be "scripted". Or at least, this is how I use "modal" on the web: queries and minor branching based on the results.
So a bit more in my thoughts:
Controller
Is the scripts (or switch mechanism) that directs to a query (modal) and then to a display (view) based on the query results
Modal
Is the data (including TO's, calculations and the queries to get/set data)
View
Is the layouts, formatting, maybe even valuelists, etc.
And, yes, there will be overlap of some of all of these in each one. It's not all a perfect system, and I'm willing to say I'm probably wrong on some of it. But I am glad that there is a blog for us to refine it!!
definfately not perfect :> )
But one of my main points is that MVC is a better fit for FileMaker than the Separation Model. It plays into FileMaker's strengths instead of against them.
But you are thinking very much like I have been about this. Controllers are well about "control". The next post on this topic is about Controllers so maybe I will withhold more on this topic until then.
We first need to build a MVC <-> FM translation dictionary
I'm not a "professional" programmer, I mean, never had formal programming training, so names like "queries", "branching", "controllers" and so on are not part of my day to day speak. However, "fields", "tables", "scripts", "calculations" are because they're part of the FileMaker lingo, which is my way of living today.
One of the "structures" I use in my system is a preferences table. There I store "common ground" stuff for all tables: Customer logo, locale settings, etc. There are also some scripts and data that are used by all modules in my system and I see them as "Services".
So, I propose that instead of talking of FileMaker files we can talk about FileMaker solutions. Then we can split those solutions into its functional parts and then find an equivalent in the MVC model. In this way we'll be able to understand completely the concept and start exploring from that point.
Re: We first need to build a MVC <-> FM translation dictionary
"queries" = "finds" (and sorts and relationships)
I use the term 'query' to mean the same as SQL queries which *can* include calculations (qty * price AS extended), sorts (ORDER BY), summaries (GROUP BY), and relationships (joins).
HTH,
Beverly
I don't know about first...
It would be nice to have a dictionary, but I don't know about "first". I am still trying to establish the validity of the idea in the first place. But once it proves useful, coming up with a translation dictionary would be very helpful.
Thanks for your comments