Faster prototypes with Just Objects Prototype

If you are like me, you need to create prototypes to see new business functionality or algorithms in action. That way we can interactively test and demonstrate a solution to customers and coworkers. The downside of many prototypes is that because they look ugly and are not easily presentable, much time can be spent to overcome those shortcomings. The problem with spending much time on making a prototype look nice is that it slows you down and prevents you from doing more meaningful work instead.
I quite often fell into this trap. I used to spend too much time working on the user interface and other rather unimportant parts of a prototype. And all of that just to make a good impression showing it off. Then I had to ask myself: How can we accelerate this? How can we prototype faster, with less ceremony and get a good enough looking functional user interface automatically?
A basic search led me towards the Naked Objects Framework which seemed like a good idea. When I wanted to test it out though, it appeared to be very complicated. I needed a much simpler, straight forward, conventions based tool. So I decided to create one myself. Behold, this is Just Objects Prototype (JOP).

Installation via NuGet is very easy. Just create a new Console Application and run “Install-Package JOP” from the package manager console. JOP uses conventions to help you focus on the logic you want to prototype. To get started, adjust your Main method to look like below.

[STAThread]
static void Main(string[] args)
{
    JustObjectsPrototype.Show.With(new object[0]);
}

When you run this code, it displays the JOP shell with nothing (no objects) in it, just like in the screenshot below.

1

As you can see, there are four parts in that window. Top most is the ribbon. It lets you create and delete object instances as well as invoke custom functionality. The left part shows a list of all the different Types, this JOP prototype knows about. If one of those Types is selected, it shows all the object instances of that Type in the top list and ribbon buttons for its static methods. When one of those object instances is selected, it shows all its properties in the bottom view and ribbon buttons for its instance methods.

Example

Lets look at an example. In this prototype I want to show a simple workflow: Suing Persons. JOP wants you to not think of anything but your object model. That is your data structures and its logic. So if we focus only on what we would need to sue persons, we may come up with persons, addresses and dossiers. And this is how that could look like in C#.

class Person
{
    public string Forename { get; set; }
    public string Surname { get; set; }
    public List<string> Nicknames { get; set; }
    public List<Address> Addresses { get; set; }
    public Dossier Sue(string why)
    {
        return new Dossier { MandateMatter = why, Culprit = this }; 
    }
    public override string ToString()
    {
        return Forename + " " + Surname 
            + (Nicknames != null && Nicknames.Any() ? " (" + string.Join(", ", Nicknames) + ")" : "");
    }
} 

class Address
{
    public string AddressText { get; set; }
}

class Dossier
{
    public bool Finalized { get; private set; }
    public string Reference { get; set; }
    public string MandateMatter { get; set; }
    public Person Culprit { get; set; }
    public void Finalize()
    {
        Finalized = !Finalized;
    }
}

These are just plain old CLR objects. Lets start the prototype with a few test instances.

var objects = new List<object>
{
    new Person { Forename = "Manuel", Surname = "Naujoks" },
    new Address { AddressText = "at home" },
    new Address { AddressText = "at work" },
    new Address { AddressText = "somewhere else" },
};
JustObjectsPrototype.Show.With(objects);

As you can see, the prototype is started with a list of objects. If we had used an Array, no new object instances could have been created since JOP tries to modify that list to keep it in sync with its internal object pool.

2

And know we see our objects in action. We can modify their properties by inserting values or reference other objects from this prototypes’ object pool. We can also invoke their methods with the ribbon buttons. When the user presses the Sue button, for example, a dialog pops up to prompt for the Sue methods’ parameters. You see that dialog in the screenshot below. Notice that we see a second ribbon button for ToString. We override the ToString method so that JOP can show a readable text when displaying a person reference in a different objects’ properties view. As far as JOP is concerned, ToString could theoretically change the objects’ state and therefore lists it as well.

3

The Sue method returns a new Dossier object. After the selected “person has been sued, the newly created dossier is available” under the Dossier type.

4

The “dossier can now be finalized” which changes the Finalized property. That property is private in code and therefore read-only on the view.

Special functionality

There are many more things JOP can do. For example mass object creation and deletion with static methods. To create many new Person object instances at once, we can introduce a dedicated method that just returns the newly created instances. To delete all Person object instances, we can introduce another method that takes an ObservableCollection as a parameter. That ObservableCollection contains all the instances of the specified type that this prototype knows of and synchronizes changes to it with the prototypes’ object pool.

public static List<Person> Create_many_persons(int how_many)
{
    return Enumerable.Range(0, how_many)
        .Select(i => new Person { Surname = "Name " + i, })
        .ToList();
}
public static void Delete_all_persons(ObservableCollection<Person> allPersons)
{
    allPersons.Clear();
}

We can allow or prohibit creation and deletion of object instances with the new and delete button by specifying a UI.Settings object when starting the prototype like below.

JustObjectsPrototype.Show.With(objects, JustObjectsPrototype.UI.Settings.New(s =>
{
    s.AllowNew[typeof(Address)] = false;
    s.AllowDelete[typeof(Address)] = false;
    s.AllowDelete[typeof(Person)] = false;
}));

Conclusion

There are many things JOP can do. In this little tutorial I showed how easy it is to develop just your object model and have JOP render a view around it. There are only a few things that require knowledge of the framework, like deletion of object instances. Even though you can create comprehensive applications with JOP, keep in mind that it is primarily focused on creating prototypes. It is very opinionated and not extensible, but it will enable you to build much better prototypes much faster.

If you like my prototyping solution, check out the Just Objects Prototype GitHub repository and feel free to suggest improvements or ask my anything on twitter at @halllo.

Advertisements

2 thoughts on “Faster prototypes with Just Objects Prototype

  1. Pingback: Dew Drop – December 28, 2015 (#2159) | Morning Dew

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s