I have an app that has subtle differences depending on where it’s being viewed.
Variations to business logic & view styles are fine – this is all handled through dependency injection & CSS respectively.
However, where I’m coming unstuck is with small variations on view layout / elements.
For example – if a user is running our application in an in-store kiosk, we use subtly different navigation options, than if they are running it in a desktop environment, or via a web browser. We may choose to hide a button, or a navigation bar.
Currently, I’m doing stuff like:
[Inject]
public var environment:Environment;
public function get labelVisible():Boolean
{
switch (environment.channel)
{
case Environment.KIOSK :
return false;
case Envirnoment.WEB :
case Envirnoment.DESKTOP :
return true;
}
}
However, I’m concerned about the Environment class leaking all over the place.
I don’t want to over-engineer something, but I’m wondering if there’s a suitable design pattern that I’m missing here that will keep me from having long switch...case or if...then‘s all over the place.
If you design your view(s) in terms of interfaces, you can handle those differences in the implementations. For example, let’s assume the
labelVisiblemethod is in a view calledLabelView. It would have a methodlabelVisible()and then you might have aKioskLabelView,WebLabelViewandDesktopLabelView. The correct view class would be injected based on the environment. Because the differences are subtle, I suspect that most of your view class(es) will be implemented in an abstract implementation with just these subtle details left to the subclass implementation.