I'm looking for some advice in dealing with UI, specifically web UI, where a multitude of different settings and toggles change what is displayed to the user. The settings are tied to the user, so each user has a unique experience (depending on a variety of factors). The existing approach of using a plethora of conditional statements; obviously doesn't scale and makes for a maintenance nightmare.
I will be implementing the MVC pattern to separate concerns, but I have to imagine there's a design pattern or best practice for configuring highly-dynamic views.
Based on user credentials, I have:
- Features that can be toggled on and off
- Features can be extended or enhanced
- Think of a checkbox list where one checkbox is not visible for one group and the whole list may be unavailable to other groups. (Like a list of options, and the user doesn't have access to all of them; maybe some are disabled, maybe some are invisible.)
The question is: how do I keep the view as clean as possible while maintaining the context and intent of the view? Do I create separate "handlers" that output specific HTML (if they are chained together through some authorization provider)? If so, how do I work with features that are shared among multiple groups, but may change slightly from one to the other?
I don't know that it matters what platform I'm developing on, so examples or suggestions in any particular language or framework are fine.
EDIT
For example, say I have ProductViewModel
(in C#):
public class ProductViewModel {
public bool DisplayPrice { get; set; }
}
In my view, then, I can check if Model.DisplayPrice == true
, and if so, display the product's price. At this level, I don't care why it's being displayed. So, this would replace something like if ( UserInRole("Vendor") || UserInRole("Distributor") )
.
Obviously I'd need some way to change this setting based on context. Ideally, I want to avoid ever having the conditional statement if ( UserInRole("Vendor") || UserInRole("Distributor") )
because the list of conditions can grow quickly. For instance, say I want to display the price to vendors, but only if they have VIP access, and have been a user for more than 30 days, and have made previous purchases, and..
Any best practices, or suggestions, for modifying/stacking the settings at runtime, per user? Anyone with experience implementing "preferences" with a huge number of permutations?