-
Book Overview & Buying
-
Table Of Contents
Tapestry 5: Building Web Applications
Currently, to provide a data source to our pages, we are using an application state object of type MockDataSource, like this:
@ApplicationState private MockDataSource dataSource;
When we request such an ASO for the first time, Tapestry takes the specified class and creates an instance of it using its no-argument constructor (naturally, such a constructor should exist). It then stores this instance into the session and gives us a reference to it.
All this works okay, but imagine that one day we have created a real data source, and so now we want to have the data source ASO like this:
@ApplicationState private RealDataSource dataSource;
We would have to find all the references to this ASO and change them then. Not impossible, but this isn't a good design. To avoid this, we create the IDataSource interface, and our MockDataSource implements it. Ideally, we would wish the ASO to be defined in a generic way, like this:
@ApplicationState private IDataSource...
Change the font size
Change margin width
Change background colour