Abstract Data Types: The Future of Scaffolding
I have seen the concept of abstract data types used to mean a number of different things. I’m using it (as Ken Pugh does in his excellent book Prefactoring) to describe the ability for a programmer to assign attributes and methods to rich custom data types like "phone number" and "social security number" (attributes and methods – see why I sometimes wish that everything was an object?!).
As Ken Pugh puts it, "don’t throw away information". A US Phone number isn’t just a varchar(10) (I’m assuming numeric digits only with no leading country code or trailing extension number for the pedantic wondering why I’m using only 10 characters) – you are throwing away a lot of information by describing it simply as a string with 10 or less digits. It should be described as a data type USPhoneNumber. You can then associate transformations (e.g. remove all non integers), validations (e.g. must be 10 digits after transformation) and from there any database requirements (such as it should be stored as a varchar(10)) and perhaps some display rules (so you can display it as xxx-xxx-xxxx automatically). You can also associate rules for displaying and processing form fields so you can automatically create (and when processing, concatenate) three different text fields in the case of a US phone number or provide a WYSIWYG editor for a "HTML" data type.
I’ll show this in action shortly, but this specific encapsulation drives a bunch of the design decisions I make in the framework as I find it to be one of the most useful and elegant patterns for quickly creating applications with rich behavior and almost no custom code.
[update] I'm starting to dislike the name "abstract data types" as for anyone with a CS background they may think of a number of things that really don't fit with what I'm trying to convey. From now I'm going to start to call them CUSTOM data types. Still the potential for misunderstanding as it doesn't clarify that these are psuedo objects with behaviors and properties, but I'm not going to go round calling them psuedo object custom data types so Custom Data Types it us, unless anyone has a better suggestion?!



There are no comments for this entry.
[Add Comment]