[TFUI] Understanding the Representation Layer

"xelcury" <[email protected]>
Newsgroups gmane.comp.programming.test-first-user-interfaces
Message-ID <[email protected]>

I'm trying to understand the concept of a "Representation Layer"
better. In the process of asking my question, I'm going to expose how
much I don't know about a large assortment of things. Please bear with
me. So, here we go.

Suppose we're building a database application for a veterinarian
office. The database tracks pets (and their owners and appointments
and whatnot). The project might be split into layers:

1) We have the data access layer. This is comprised of classes that
retrieve and save data to a database, say a Microsoft Access database.

2) Then we have the business object layer. This is comprised of
classes that give us an easy, object-oriented way of dealing with data
from the database. Here is one of our classes:

Pet
---
Properties: Name, Id, Species, HairColor, BirthDate, etc.
Methods: Save, LoadFromID

The business object layer can do data validation. For example, say
HairColor is never allowed to be set to "orange" if the Species is set
to "ferret". The Pet object can throw an exception if you try to set
HairColor to "orange" if the Species was already set to "ferret". The
gui is expected to deal with that exception in an intelligent way.

3) Next we have our gui -- the forms that the users see. Here is one
of these classes:

PetForm
-------
Controls on the form: textboxPetName, textboxId, comboboxSpecies,
comboboxHairColor, datepickerBirthDate, etc.

The "non-humble" way of doing things is to somehow bind the controls
in PetForm to the related properties of a Pet object. So in the
constructor for PetForm, we might have...

Pet currentPet = New Pet();
Bind(textboxPetName, currentPet.Name);
Bind(textboxId, currentPet.Id);
Bind(comboboxSpecies, currentPet.Species);
Bind(comboboxHairColor, currentPet.HairColor);
currentPet.LoadFromID(petID);

4) So, we come to the "representation layer".

I understand that it is meant to fall between the gui and the business
objects. We add a new class:

PetFormRepresentation
----------------------
Properties: TextBoxRepresentativePetName,
ComboBoxRepresentativeSpecies, etc

A TextBoxRepresentative is an object that represents a TextBox, except
it never draws anything on the screen. It has a "Text" property just
like a TextBox, and all the same events. 

Somehow TextBoxRepresentativePetName in PetFormRepresentation gets
bound to textboxPetName in PetForm. And somehow PetFormRepresentation
is in turn bound to a Pet object.

How far off is that?

-Patrick






To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/TestFirstUserInterfaces/

<*> To unsubscribe from this group, send an email to:
    TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.