As mentioned when we talked about three-tier systems, one of the key aspects is keeping elements separated so they can be updated/changed.
You may have different User Interfaces, such as Web, Mobile, and even Desktop Applications, which can all co-exist because they call to load info from the business logic server (sometimes called app server) without it worrying how the data will be displayed.
Likewise, you can move from one data source to another. A common method is to use a Data Access object, which will return the object of the data type you want. However, how it does that, is up to it. So for example, you might have a plain text file, or a serialized data file, or a Database, or a network source etc.
Note: You will find that the Data Access classes tend to utilize a Singleton design pattern. This is something we talk about in an upcoming module.
The ability for the application to switch between sources should only affect that first (data) tier and how you get to it. The business logic and UI shouldn’t worry about it, since it is dependent upon completely different components.
Due to the “black box” nature of a well designed OOP, you just need to worry about the access points to create the other components and have it working correctly.
This will often mean your Data Access object will look something like:
public UserDA {
private static Vector<User> users = null;
private static checkForData() {
if(UserDA.users == null) {
// do stuff to load in user data
}
}
public static User findUser(String searchCriteria) {
User user = null;
UserDA.checkForData();
// get user as needed by this method
return user;
}
public static void addUser(User newUser) {
// convert newUser to the data storage method
// this is the Create method from the CRUD list of methods
return;
}
// .... etc ....
}
Interchangeable Sources was originally found on Access 2 Learn