Sadek Drobi’s Blog

November 22, 2006

OBSEV: Model View Presenter w/Command (DataGrid)

Filed under: Architecture, MVP — Sadache @ 4:21 pm

This weekent went fast, i didnt really have time to work on a sample code . Here i post a sketch, a class and a sequence diagram, showing an example of Model View Presenter with a command pattern implementation , for a datagrid.

The initBinder method on the binderObject subscribes it to the deffirent events of the datagrid.

then treatement can be added for the deffirent events.

DataBinders with xml mappping can be provided, so that reflexion can be used to map model to the dataBinderObject at run time. (more…)

OBSEV :: SOA and Orchestration with .net 3.0’s WCF / WF

Filed under: Architecture, SOA, WCF, WF — Sadache @ 3:50 pm

I promised Demos for the .net 3.0, and here is my first and simplest J

Talking SOA, there are several important principles about it, one of them ORCHESTRATION.

Business Logic is never Logical (martin fowler) , so it could be a good idea to externalize this “logic” and make it so easy to do composing services from lower layers in the application architecture, this way, you offer your client an easy tool, to compose reusable services to form the needed business process.

That what Orchestration is somehow about, one important standard implementation is BPEL, an XML representation of the services composition, and thats were my demo starts. (more…)

Generics : Be Carefull OF Overloading, and DONT forget Object Orientation

Filed under: C# — Sadache @ 3:27 pm

I am thankful for Mitsu Furuta’s Presentation about generics, and then for his answers to my question in his blog.

Acutely i am always happy to follow Mitsu’s presentation. He is always very accurate, each word he puts on his PPT is important, and has a meaning, a very important one!

The presentation i am talking about was about C# 2.0 , on of the things he discussed was generics ,and one of the slides had two extremely important sentences : be careful with methods overloads, and dont forget about Object orientation.

Problem:

Reading this i remembered the issue i got in C# in generic collections. specifically in IDictionary, my problems with this class were the following:

1: Dictionary implements IDictionary and the non generic IDictionary.

so u can make something like

IDictionary d=new Dictionary;

then cast it like this

IDictionary d1=(IDictionary)d;

so inserting here any object in the IDictionary will throw a runtime exception, and no compile time check is done! ( see why is it done like this below)

2:using the operator [] on the first instance (the generic one) with a key that doesnt exist will throw an exception, whereas doing the same with the no generic one will just return null!

int i=d1k] throws exception if k doesnt exist

object o=d1[k]  return null if k doesnt exist

so imagine having IDictionary , isnt the signature of the [] operator identical with the one of the non generic IDictionary?

then i told myself “what a bizarre compiler!”.

so i told my self (whats the! two different behavior for the same method in the same class??? how come!)

Explantation:

in the case number 1, Mitsu cleared it out for me! DONT FORGET OBJECT ORIENTATION! Deferent type of a generic task has nothing in common, they just look the same, but there is no inheritance, no polymorphism, so YES , you need to implement the same interface, to be able to call polymorphically the methods of that interface!

and about the two behavior of the [] operator in IDictionary and IDictionary, YES they can have the same signature BUT THIS IS EXPLICITE INHERITANCE!

explicit inheritance is a feature in C# where u can implement the same method , differently for different classes, by using InterfaceName.Method();

i didnt know this feature before, the two methods live in different scopes in the class, so there is no overloading.

but anyway, u should be careful about generics, any static field or method is static per closed type and not per generic class.

and also be careful about overloading, especially after closing the class with the type.

thanks mitsu! :)

OBSEV: Model View Presenter w/Command (sadek)

Filed under: Architecture, MVP — Sadache @ 3:20 pm
Thinking about Martin’s Article, and the MSDN extension of MVP,I realize the importance of this pattern. I even see that a whole extension framework can be built on this pattern, I will explain more…
I believe in the dumb view, a view that doesn’t contain any logic, not even data binding.
Martin’s MVP together with the MSDN’s article answered several questions, and showed ways to keep the view really clean, but we sacrifice ASP.net’s productivity (DataSource xml mappers, binding mechanism…etc )
But here comes a question, should we really sacrifice all of that? The answer is yes and no!
In my point of view, yes we should avoid putting logic in the page handler, I know that wizards are easier, but they are not healthier! This binding and mapping mechanism live in the code behind, which is not unit tested, that means a source code that can grow buggy, and yet not covered by the tests.
But the good news is, No we don’t have to forget about productivity, as long as we are capable of creating our healthy ways to do it.
In my observation I will try to suggest solutions to these kind of problems, u are free to take it, to like it, or not. Anyway any comment will be helpful to develop the solution.
My solution is inherited from the Command Pattern (GoF).
Back to the dumb view, so we move all the logic to the presenter, and we leave the code behind with properties and events, and we subscribe the presenter to these events.
The DataBinding is done by a command object, actually I am calling it command just to remind that all commands share the same interface, with one method (the Execute() method) and these commands encapsulate  the logic.
I don’t guess that sticking to the strict definition of the command pattern is important, we can have the Interface having more than one method, the most important thing, is to share the interface with one or more executing methods .
Following sketch is a class diagram and a sequence diagram that illustrates the interaction between the the page (view) , the presenter, the command and the model.
The benefits of such a model is to avoid code duplication by providing the data binding  logic , encapsulating it inside  a class, and providing the possibility of implementing an xml mapping to the model (using app.config or even custom configuration files that look like the asp.net DataSource mapping).
This example is quite simple and straightforward as it is about the simplest databinding (which is to a drop down list)
Later I will provide another observation , with a more sophisticated example, illustrating more functionalities (update,delete,edit).
 
    

 

Refx >> Model-View-Presenter for Asp.net

Filed under: Architecture, MVP — Sadache @ 3:15 pm
Martin Fowler talked about the Model-View-Presenter in his blog , then he came back and splitted it into 3 patterns :
 Presentation Model, Supervising Controller, Passive View
The degree of seperation between model, controller and view varies in each of the three.
I recommend reading Martin’s articles about the MVP for deeper understanding of the patterns.
Follows is a REFLECTION, an article in msdn Magazine, implementing the MVP in asp.net, quite interesting, Especially on this event based web framework.
The author chose to present the Model View Presenter using Test Driven Development, pointing it out (MVP) as solution for implementing the TDD approach in asp.net .

What is Reflections-Observations

Filed under: Uncategorized — Sadache @ 2:20 pm

hello world!!!
Reflections-Observations is a website that i am doing, but didnt release it yet. 
What is a Reflection ?  We are reading ll the time, discovering new things, a reflection is a representation of an article, paragraph, book, video, webcast etc…to point out the key points it has.Why Reflection?    Personally i work in IT field, i read materials, that i feel important.A refletion is a way and a method to share knowledge, then to add my own observation to it.

Actuelly the idea of the coming web site, is to be a place for people to add their reflections, then others add their observations or comments to it.
Here i should point out a deffirence, an observations is not a comment.   

An observation adds to the reflection something related to the reflector’s knowledge, which means he develops the original idea. Whereas comment is an opinion or a point of view. 

Observation treats the subjects and develops its content.
For now i am the only Reflector/Observer, but in the website everyone will be.    

I will use conventions in this blog, so i start a reflection text with Refx and the observation with Obsev.Hope you’re comfortable with the shortcuts.The content will be mostly related to programming/architecture, but that doesnt mean there will be no other.
Regards    

Sadek Drobi

Powered by WordPress