Binary heap based priority queue

Design of container that supports items ordering raises lots of interesting design questions to consider. To be more concrete we will design simple priority queue based on binary min heap that supports the following operations: Enqueue – add an item to the queue with an associated priority. Dequeue – remove the element from the queue…


Disposing sequence of resources with Reactive Extensions

Recall my previous post on Disposing sequence of resources where we were solving imperatively the following problems: Create single disposable representation for a sequence of disposable resources Defer resources allocation to avoid exception propagation until cleanup can be guaranteed and avoid unnecessary (allocated resources that aren’t used) allocations Dispose only consumed resources and preserve nested…


Chaining responsibilities

The idea behind Chain of Responsibility pattern is quite simple and powerful: Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. You can find lots of…


Making callbacks more explicit

Recall my previous post Events and Callbacks vs. Explicit Calls that outlined pros and cons of both (events and callbacks on one side and explicit calls on the other side) approaches. Explicit calls imply that callee plays certain role from caller’s perspective thus making the relationship between the two explicit as well. Consider simple undo/redo…


Disposing sequence of resources

C# “using” statement has several advantages over its expanded equivalent: Shortcut is more readable If local variable form for resource acquisition is used it is read-only inside using statement and thus prevents you from spoiling resource disposal Whenever you need to obtain several resources (number is known at compile time), use and then dispose them…