Posts

Showing posts with the label Observer Pattern

Design Patterns Series 20 - Double Buffer, Recycle Bin, and MVC Patterns

In this post we will explore the last three patterns in our design patterns list, Double Buffer Pattern , Recycle Bin Pattern , and Model/View/Controller (MVC) Pattern. Double Buffer Pattern : Double Buffering is used to avoid screen flicker when you are displaying graphics. The idea is that you perfrom your multi-step graphics creation off-screen in a buffer and then flash the results on the screen when they're complete. The process is called Double Buffering  because the screen display buffer is one buffer and the buffer in which the images are prepared is the second buffer. Use a Double Buffer  when generating revised datasets for an asynchronous processor. When the new data is complete and self consistent, redirect the asynchronous processor to the alternate buffer. Recycle Bin Pattern : If your code uses many objects and the object-creation process is time - and resource - intensive, you might want to use the Recycle Bin Pattern . The idea is that when you're do...

Design Patterns Series 5 - Observer Pattern

We talked about Factory pattern in previous post  ,in this post we will discover one of design patterns that keep your object  know when something has happened and passing a notification to an observer. Actually there is two design pattern do this job, Observer Pattern and Chain of Responsibilities pattern . Observer Pattern : It lets several observer objects be notified when a subject object is changed in some way, each observer registers with the subject and when a change occurs the subject notifies them all in parallel (yes at the same time). The observer design pattern should " define a one-to-many dependency between objects so that when one object changes state, all its dependants are notified and updated automatically  ". You should consider the observer design pattern when you have an object that can cause events to occur - events that you want other objects to know about. Instead of writing everything in one monolithic class, consider ...