The Bridge pattern is ideal for building cross-platform applications. By completely separating the class interface from the implementation, programs can interchange the actual implementation of a particular subsystem without requiring any changes in other parts of the code.
Continue reading
Tag Archives: Software Sagacity
C# Design Patterns: #6 – Adapter
The Adapter pattern helps provide a better way to leverage existing code. Instead of requiring the developer to redesign components from scratch, the Adapter can integrate work from previous projects or other libraries.
Continue reading
C# Design Patterns: #5 – Builder
The Builder pattern is a narrowly-focused pattern that enables incremental creation of new products. This pattern, though limited in application, when applied correctly, brings significant power and flexibility.
The guiding concept behind the Builder pattern is separation of the actual “building” of an product from its design plan. The prototypical example of the builder pattern is saving files to multiple formats. If an application allows saving files to different formats, it will have an internal representation of the data, and will need to “build” different formats dynamically from the same source object.
Continue reading
C# Design Patterns: #4 – Abstract Factory
The Abstract Factory pattern, although not present in many end-user applications, finds ample grace in the development of user-configurable toolkits and frameworks. Instead of locking the developer into a particular set of controls or objects that will be used by the framework, the abstract factory instead lets developers substitute their own controls when necessary.
Continue reading
C# Design Patterns: #3 – The Prototype
What do CAD design tools, workflow automation, and digital audio synthesizers have in common? They can all benefit from the Prototype pattern in their software architecture.
Although the Prototype pattern achieves true glory in languages such as JavaScript, which base their entire class structures on Prototypes instead of traditional classes, the pattern still brings powerful functionality to C#. Its primary use is in a very specific niche: when the users of the application will perform design work, and then group those designs into reusable subcomponents.
Continue reading
C# Design Patterns: #2 – The Factory Method
One of the less useful C# design patterns is the Factory Method. Primarily used for framework and toolkit development, this design pattern is rarely used in a language like C# that has templated classes, anonymous functions, interfaces, and reflection.
Continue reading
C# Design Patterns: #1 – The Singleton
The Singleton is one of the simpler design patterns. As the name suggests, the Singleton creates a single, static, globally accessible class. It is an alternative to global variables and static classes, each which come with their own limitations.
Singletons are excellent areas to store global information, such as database connection strings, system paths, and parsed XML configurations. In addition, Singletons can be used to store global image caches so that images can be shared between functions.
Continue reading
C# DirectX – Capturing Frame Screenshots
Screen capture in DirectX is an inconspicuous element of the rendering pipeline that can provide many auxiliary benefits to 3D applications. Through creative use of the screen capture functionality, the operation can be extended to not just video creation, but also multi-stage graphics and post-processing. At its core is the code that enables capture of the current frame in the rendering process.
When programming screenshots, the most important element is placing the code at the correct point in the render loop. A poorly integrated screenshot function can cause instability and system crashes in the 3D application due to race conditions or memory overwrite.
Continue reading
Debugging .NET Memory Leaks with ANTS Memory Profiler
Memory leaks in .NET can be a challenging problem to both identify and solve. While C and C++ programs make memory management a constant concern during development, C# touts its garbage collector as the end to memory management and an easier way to program. Unfortunately, there are times when the C# garbage collector does not work as expected, resulting in applications that randomly crash after extended use.
Continue reading
Automatic Solution Packaging with the C# Preprocessor
The C# preprocessor, although much less powerful than the C or C++ preprocessors, still provides the ability to enable or disable lines of code based on project-level flags. In addition, when combined with external PowerShell scripts, the C# preprocessor can be used to automatically spin custom C# solutions with subsets of the target code. This can be particularly useful when providing two versions of the source code, for instance a 32-bit and 64-bit version, or when creating custom source code adaptations for different applications.
Continue reading