Conclusion Don t Reinvent the Wheel
This chapter introduces .NET's platform invocation service, a powerful technology that enables the integration of native, unmanaged, and even hardware accelerated code into .NET applications.
PInvoke may play a key role in the acceptance of .NET as a new development platform in many companies because it allows the reuse of software components, even those that were not developed for the .NET Frame work. Today, when the "better, faster, cheaper" principle is imposed on nearly every project, it is a necessity to build new versions of an application by using components of the older version. Furthermore, you can't avoid sharing components across multiple applications to cut down development time and maintenance costs. For example, Adobe uses a dialog manager component that offers common user interfaces that can be found in many of Adobe's products, including Photoshop, Illustrator, and Framemaker.
Nevertheless, there are some pitfalls to watch out for before you reuse or design reusable software components:
- New applications can profit from the robustness of existing components and will be deployed with fewer bugs. However, the opposite effect can occur if the reused code has not been well tested. In that case, all applications using this code will have inferior stability.
- Despite the advantages that code reuse can bring, it can also lead to mental blocks when you design a new system. By trying to reuse legacy code, you may also unintentionally adopt previous analyses and designs, perhaps overlooking a simpler solution.
- When you are developing reusable software building blocks, you must pay greater attention, and that leads to increased initial development time and cost. You must consider these costs in the project planning when such a component is built for the first time.
- Trying to think "strategically" and designing a software component to be ready for future extensions as well as reusability in other applications may lead to unnecessarily complex, overengineered designs. Adding too many layers for abstraction, separation, or interfaces may open the door to new bugs in these layers. Always remember that there are also other good practicesfor example, keeping things simple.