Garo Garabedyan- a private blog

Everything here is written and belongs to me except otherwise noted.

Posts Tagged ‘Observer Pattern

eventBased Framework

with one comment

(Documentation in Bulgarian) http://unidevelop.org/wiki/project_embedded_apps_lib

(SVN Project home) http://unidevelop.org/browser/unidevelop/programming/projects/eventBasedFramework

I have wrote a small C OpenSource licensed framework implementing the ideas of eventBased Algorithms and Data and Data flow processing (http://garabedyan.wordpress.com/2008/03/04/data-flow-processing-eventbased-algorithms-and-data/) for my university exams. I have win first place best programming project in Unidevelop, Technical University- Sofia, the organizers granted me an ASUS EEE PC 4GB which event was presented in the front page of New technical avangard (official newspaper of Technical Univesity, Bulgaria) in February 2009.

The framework is aimed to handle embedded applications, but its core is universal in the context of the expressed assumptions about Object Oriented Programming (state and behaviour) eventBased Data processing (Observer pattern). Client- programmer is able to easily create variable containers and declare to them the interested functions in a change of the stored variable. Every time a variable value is changed the interested functions are informed.

Future development of the project is adding Aspect-Oriented like functionality which to enable the client- programmer to declare aspects (functions) and functions (or aspects) to be called before and after the aspect’s code is executed. Very useful to be aspects I think functions which produce outside the MCU commands.

I have used Erik Meijer: Functional Programming; MSDN Channel 9 Going Deep Show http://channel9.msdn.com/shows/Going+Deep/Erik-Meijer-Functional-Programming/ as an additional theoretical source of programming language science.

The client- programmer uses the platform as a library for calculating decision tree finding the right result in as a small period of calculation time, as possible; optimization of calculation in the program which depends on external variables (especially for those which are part of the decision tree if meet the letter condition) by in advance calculation in every change (revision) of the value of a variable.

eventBased Framework is a platform architecture aimed to advocate declarative programming in programming products handling asynchronous events.

I believe that the architecture of a program must inherit the structure of a natural science like Physics in example. There is a pure scientific explanation within the idea of of declaring and defining by such formulas in small modules source code. Programming is of its own translation (virtualization) of a real phenomena in electronic form, which is all what natural science do. The history of development (introducing new more concrete ideas and visions) of sciences goes through this process. Science tries to generalize and collect “if-then” observations describing behavior of a certain class phenomenas by transforming them into laws predicting result of a system in a moment in future. This laws have such mathematical form to enable calculation and analyze.

As far as Object Oriented Programming is an engagement of state and behavior, object oriented code can be written in languages which does not support insight mechanisms of encapsulation, powerful polymorphism with class interfaces and casting. Using methods of memory addressing with references and addressing code pieces with references to functions, engagement of state and behavior can be reached. This source code is reusable (re-editable) in a result of this OOP powerful character.

MCUs during their work handle input events. From this point of view a certain amount of variables exists, which is defined with input/ output functions important for the behavior of the system.

It is strongly recommended (close to restriction) functions called in advance to not result in hardware commands outside the MCU. Such side effects are supposed to be coordinated with the purpose of the concrete technical system.
In order achieving optimization, it is important every significant heavy calculating function to save (declare) all its input and output variables (including code side effects and dependency injection) in the global dynamic array of containers of variables (implemented by eventBased Framework) meanwhile to register its interest of all input variables in their concrete containers. When such code is called it must immediately return the execution of the program after checking if the input variables’ values have been already examined by the code.

Conclusion: Multi- stage programming and object’s oriented most significant functionality of encapsulation of state and behavior are implemented intelligently in one homogeneous software architecture unit enabling interruptions for reacting on urgent events. In parallel to reaction on every small change of some value in variable containers, the client- programmer can write functions reacting on interruptions which code on a base of small calculations of the present values in variable containers to calculate the needed reaction on the urgent situation.

Written by garabedyan

December 17, 2008 at 17:46

java.lang.ref.* in GoogleWebToolkit ?

without comments

Is java.lang.ref.* functioning in GWT? I come to an idea that java.lang.ref.* is necessary to enable proper garbage collection while implementing the Observer pattern in Model View Controller.

I was writing a big Java code for GWT for my school final project to make a program that at that days was modern to call Rich Internet Applications (RIA). I have implemented the full MVC by making the model to be a fully functional object (at that time only a Bean object carrier but able to implement business logic if having this need in future) which updates by request to the server made in a definite period of time. I have enabled different views to edit at one time one object by implementing the Observer pattern. After I have finished the project I realized that a newly created view will never be collected by the garbage collector because always its model has a reference to it in order to update it when an update is received from the server.

Now I think that by implementing java.lang.ref.* in the client side (translating to written by hand JavaScript code that adds and can manages new type of object references) many people can avoid their own implementation of object release algorithm used to classify the significant (regular) and not significant (which do not require object existance at all) object references.

Link to GoogleWebToolkit Discussion Forum thread on “java.lang.ref.* in GoogleWebToolkit ?”.

Garbage collection in Java and design patterns http://garabedyan.wordpress.com/2008/01/08/garbage-collection-in-java-and-design-patterns/

Written by garabedyan

November 18, 2008 at 09:21

Garbage Collection in Java and Design Patterns

with 2 comments

Managing object deletion in Java is made automatically by Garbage Collector. Having this in mind it is crucial to know how to implement some patterns (like the Observer) which has a communication line (realized with storing refs) between objects.

Instead of the default object reference I offer you to use java.lang.ref.*

It is important to use not default object references in order instruct Garbage Collector to delete the object when up to him are only weak object references (which refs are supposed to keep the object in some pattern but not to keep it away of Garbage Collector).

Written by garabedyan

January 8, 2008 at 22:05