Archive for the 'News' Category

Principle of Least Knowledge

Saturday, February 2nd, 2008

One very important (yet often overlooked) design guideline which I advocate is the Principle of least knowledge.

The Principle of Least knowledge, also known as The law of Demeter, or more precisely, the Law of Demeter for Functions/Methods (LoD-F) is a design principle which provides guidelines for designing a system with minimal dependencies. It is typically summarized as “Only talk to your immediate friends.”

What this means is a client should only have knowledge of an objects members, and not have access to properties and methods of other objects via the members. To put it in simple terms you should only have access to the members of the object, and nothing beyond that. Think if it like this: if you use more than 1 dot you are violating the principle.

Consider the following: We have three classes: ClassA, ClassB and ClassC. ClassA has an instance member of type ClassB. ClassB has an instance member of type ClassC. This can be designed in such a way which allows direct access all the way down the dependency chain to ClassC or beyond, as in the following example:

// ClassA defines a member of type ClassB and provides
// access to the instance
public class ClassA
{
    private var b:ClassB;
   
    public function getB() : ClassB
    {
         return b;
    }
}

// ClassB defines a member of type ClassC and provides
// access to the instance
public class ClassB
{
    private var c:ClassC = new ClassC();
   
    public function getC() : ClassC
    {
         return c;
    }
}

// ClassC could expose additional members and on and
// on creating more and more direct dependencies
public class ClassC
{
    public someType:SomeType;
    …
}

// client implementation
var a:ClassA = new ClassA();
var sometype:SomeType = a.getB().getC().someType;
 

The above example is quite common, however it violates The Principle of Least Knowledge as it creates multiple dependencies, thus reducing maintainability as should the internal structure of ClassA need to change so would all instances of ClassA.

Now keep in mind that in all software development there are trade-offs to some degree. Sometimes performance trumps maintainability or vice-versa, other times readability trumps both. A perfect example of where you would not want to use The Principle of Least Knowledge is in a Cairngorm ModelLocator implementation. The Cairngorm ModelLocator violates the Principle of least knowledge for good reason - it simply would not be practical to write wrapper methods for every object on the ModelLocator. This is the main drawback of the Principle of least Knowledge; the need to create wrapper methods for each object, which are more formally known as Demeter Transmogrifiers.

The goal of good software design is to minimize dependencies, and by carefully following the guidelines provided by The Principle of Least Knowledge this becomes much easier to accomplish.

SQLite Administrator

Thursday, January 24th, 2008

When developing application in Adobe AIR which utilize the SQLite API it is often useful to have a quality SQLite editor available, especially during development and testing.

I have tried many different SQLite editors, most of which were quite good, however the best of the bunch you have to pay for.

Personally I recommend SQLite Administrator. SQLite Administrator is a powerful tool which allows for the design, creation and modification of local SQLite databases. The code editor is very intuitive and provides a simple UI which allows you to write SQL queries with little effort. In addition, there are many useful features which you would expect from a quality editor such as code completion and highlighting.

SQLite Administrator

So if you are looking for an high quality free SQLite Editor when working with Adobe AIR and SQLite check out SQLite Administrator

InsideRIA.com

Wednesday, January 23rd, 2008

InsideRIA.com

O’Reilly and Adobe have teamed up to create an invaluable online community for RIA developers. This new project will provide up-to-date information on the ever-changing state of design and development in the Rich Internet Applications (RIAs) space.

Rich Tretola will be championing the effort for InsideRIA as the Community Manager.

Show your support so we can make InsideRIA the number one place on the Internet for Rich Internet Application resources and information.

Quick Tip: Flex 3 IDE

Saturday, January 5th, 2008

I have added a new Category to my blog called “Quick Tips” from which I plan to post various quick and simple, yet useful little things I come across from time to time.

This first Quick Tip has to do with the default state of the “Mark occurrences feature” in Flex Builder 3 (the feature which causes all methods, properties etc to be highlighted in blue).

Upon installation of the latest Flex 3 beta one of the initial features I noticed was the Mark occurrences feature. Personally I found it to be quite annoying and somewhat intrusive. In addition the feature was also pretty slow (however I believe this is currently being addressed).

In any event I wanted to disable this feature, problem was I couldn’t figure out exactly how to turn it off! After some exploring in the preferences panel I was still unable to find where the Mark occurrences feature could be disabled, so I posted a new topic on the Flex 3 pre-release forum, and luckily I got a quick response from Laurence Mclister explaining where the feature could be disabled - it was right there in the toolbar!

Mark occurrences can be turned off via the toolbar button which looks like a yellow highlighter it is typically toward the center of the toolbar). Below I have highlighted in red where the Mark occurrences feature is located on the toolbar.

Mark Occurrences

Hope that saves someone some time down the road.