Alex’s Weblog

My personal blog

Decorators Design Pattern

In the last days I have been designing some programs. I will have to do it in the master program, since we’re going to change a lot of the program made so far. So I decide to study some O.O. and nothing better than Design Pattern to improve my O.O. expertise. Today I want talk some about the Decorator Design Pattern.

Everybody that have already read some advanced O.O. articles knows about the nasty characteristics of the inheritance[1][2]. I don’t agree with all these, but when we start to study we’re more able to understand their points. The over uses of inheritance leads us to less flexible and maintainable designs. Other point is that we will have static behavior (compile time implemented) and using Composition we can have dynamic behavior.

Dynamic behavior could be mandatory in some design or you would be crazy in a big number of classes. For instance, if you have a Window class with Horizontal Bars, Vertical Bars, both or none. You could create a class for each case, but is not difficult to imagine that this problem could be large and leads to a impossible number of classes.

Let’s see the solution using decorators First we’ll start with a diagram of the Decorators Design pattern

 

Using this design pattern you can create objects that combine the others behavior for example if I want a object with both scroll bars:

Widget* aWidget = new HorizontalScrollBarDecorator ( VerticalScrollBarDecorator( SimpleWindow()));

 

This pattern is used also in the JAVA API. Look the InputStream Implementation [4 – Decorators subsection].

This post it is not too much useful alone, but it has good references…. If is necessary comment it.

 

1 – Inheritance is evil, and must be destroyed: part 1 – http://www.berniecode.com/writing/inheritance/

2 – Why extends is evil – http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html

3 – Decorator pattern – http://en.wikipedia.org/wiki/Decorator_pattern

4 – Solve the date-selection problem once and for all – http://www.javaworld.com/javaworld/jw-07-2003/jw-0704-toolbox.html

Dezembro 4, 2008 Publicado por alexpinheiro | UML | | Sem comentários ainda

Difference Between Frames and Description Logic

This post has the goal to discuss in few lines the differences between Frames Technology and Description Logic Based Languages. For the ones that don’t know these terms, OO languanges are Frame based, and OWL is a Description Logic Language. The differences between this two worlds are important because when we are working with ontologies it is a common practice model in a O.O. modeling language (UML) and later translate it to a Description Logic Language (OWL-lite or OWL-DL). If we aren’t aware of the differences between the two worlds we can have some problems when doing the mapping between the model and its implementation.

A DL terminology includes a set of primitive concepts and roles(properties) as well as definitions of complex concepts and roles. The definitions of complex concepts and roles are given via descriptions that are built using a set of constructors, which vary from one DL to another. The strength of DLs is that they are associated with algorithms for subsumption checking, automatic classification and instance recognition.[1]

Frame logic (FL) accounts in a clean, declarative fashion for most of the structural aspects of object-oriented and frame based languages[3]. F-logic stands in the same relationship to the object oriented paradigm as classical predicate calculus stands to relational programming. Although the Frames Technology most well known example is the OO programming languages, there are some ontology languages based on Frames, one example is F-Logic, and the Protégé itself one of the most known ontology editors is based on frames. There is also a reasoner to F-Logic called Florida[2].

  • DLs rely on the ontological distinction between concepts and elements. FL blows away this distinction.
  • FL: closed-world and domain-closure assumptions. DL: open-world and open-domain assumptions.
  • FL: class definition necessary and sufficient.
  • DL don’t uses the unique name assumptions[4] whereas FL includes term equality.
  • DL don’t provides control knowledge. The user it is only able to provide declarative knowledge.

I need to do some research yet to understand how protégé works since it is a frame based editor, but OWL more used is the OWL-DL.

[1] D. Fensel, M.-C. Rousset and S. Decker – Workshop on Comparing Description and Frame Logics

[2] http://en.wikipedia.org/wiki/F-logic

[3] Logical Foundations of Object Oriented and Frame Based Languages – Michael Kifer, Georg Lausen and James Wu

[4] http://en.wikipedia.org/wiki/Description_logic

Novembro 18, 2008 Publicado por alexpinheiro | Modelling, Uncategorized | , , | Sem comentários ainda