Tips for the Business-Services Tier
Designing Objects for Reuse
Question
The BDG documentation specifically states that n-tier is where n is greater than 2 for a Windows DNA application. Is there an approved approach that allows for maximum code reuse where n is 1? I am trying to find the best approach for maximum code reuse across a broad line of architectures to include desktop, intranet, and Internet.
Our Response
This is an interesting question. Consider the viewpoint that object reuse has nothing to do with n-tier programming, per se. Reusable binary objects (such as those that COM produces) are extremely important to n-tier development, but not vice versa. Here are a few tips to keep in mind as you design your object for reuse:
- Maximum code reuse can only be achieved by decoupling the object from its environment. A flexible interface uses standard data types (including VARIANT data types where necessary) and performs discrete well-defined activities. Combining presentation, business logic, and data access into a single component guarantees that you will NOT be able to reuse the component successfully. Rather, you should build generic objects for presentation (user interface), custom business objects for your program logic, and standardized data access objects that can retrieve data from a variety of sources.
- Don't build your objects with a single use in mind. This is especially true if you are building a component that will be used by multiple teams. Get a full list of features from each of your clients before you begin to design your interface.
- Avoid object state wherever possible. This allows your object to be reused in environments that normally do not maintain state, like MTS and RDS.
Creating COM Objects with MTS
Whether to create COM objects with MTS (using the MTS.CreateInstance method) has been a topic of some controversy. For more information on this issue, see About Creating COM Objects in MTS.