Skip to main content

Posts

Showing posts from January, 2016

Proxy Pattern : Real Life Example and Java Code Example

Proxy Pattern The proxy pattern defines how to get object level access control by acting as a pass through entity or a placeholder object. There are three types in the proxy pattern. (1) Remote Proxy: Remote proxy represents an object locally which belongs to a different remote location. Real Life Example: ATM is remote proxy for the banks. (2) Virtual Proxy: When an object is complex or heavy, We can use a virtual proxy object as a skeleton representation for the original object. Real Life Example: Bank Cheques are the Virtual Proxy for the Currency Notes. (3) Protection Proxy: When we use a proxy to restrict the access of object it's called Protection proxy. Real Life Example: Proxy servers used in office and organizations to block the access of some websites and networks Java Code Example: Below is the java code example for the ATM Bank Implementation(Remote Proxy). The below code is not very good and secure for sophisticated banking system and

Volatile Qualifier in C : Explained by Example

                      V olatie qualifier can be used by keyword volatile in C/C++. You can define a variable as volatile by adding volatile qualifier just before data type.eg volatile int a; Volatile specifies a variable whose value may be changed by processes outside the current program. The meaning of outside of the current program may be Operating System or separate thread in case of multi threading processing. When we defines a variable as volatile, It does two things 1) The system always reads the current value of a volatile object from the memory location rather than keeping its value in temporary register at the point it is requested, even if a previous instruction asked for a value from the same object. 2) It stops Compiler to perform some optimizations. As we know that Compiler do some kind of optimizations on the source code before compilation. Below examples explain how a volatile qualifier affects the Compiler optimizations. Suppose There is the following So