Saturday, June 20, 2009

Conky version 1.0


It's finished! I'm still working on some details: the icons are ok, but I wonder if I could cut this down a bit. I also want to divide this up to all 4 corners of my screen.

Anyway, this is the conky in #! on my laptop. The smudged content in the top is my hostname 'on' my ESSID. If the ESSID isn't available (e.g. no wireless connection), it prints " is disconnected"

Friday, June 19, 2009

Nuts, Conky isn't working right


Here's a snippet of a Conky config I've been working on.

Friday, June 12, 2009

Dependency Injection and Flex

So, a quick note on the progress I've made with Flex. First of all, I wanted a tool to highlight text. So...I spent 3 weeks working through tutorials and examples from some brilliant coders who have already paved this way, worked with several different libraries, and finally found that all my work was for naught; enter, FlexLib. It not only had a great highlighting class, but also contained some moveable Panels, and a nice extensible Tab Navigator...sigh..all that work down the drain.

Anyway, I've heard about Dependency Injections a lot lately, and I finally decided to research what it's about. Wow, I never realized how simple a concept it would be. Having been exposed to different design patterns like Factory Method, this was extremely easy to assimilate.

Dependency Injection works very well with Flex interfaces, and particularly well with Factories. If I have an object A which depends on object B, I could have A instantiate B and maintain a reference to it. Unfortunately, this creates a dependency within A upon B:

private var bInstance:B;
...
bInstance = new B();
bInstance.foo();


In this case, A has a definite dependency upon B's implementation. If B changes 'foo()' to anything else, A will break.

We can partially solve this via a interface, in which A and B agree on B's required methods. In this case, B utilizes an interface, BI, which instructs B to always implement 'foo()'. Thus, A can access B via its instance:

private var bInstance:BI;
...
bInstance = new B();
bInstance.foo(); //guaranteed since bInstance is an instance of type BI


But we still have a problem: A is still relying on the base class of B. What if we wanted to break B into different objects, and 'B' was no longer a valid name? Moreover, what if we moved B to a different library? Enter a factory.

Rather than A creating B, even via its interface, what if the code calling A passed in a reference to B, via its interface? For this, we'll add two new classes. 'Factory' has a 'createBI' function that returns a reference to B via its interface, BI. FooBar is a class which creates A. In this class, the code to create A might look something like this:

a = new A(Factory.createBI());


Whereas the constructor for A might look like this:

private bInst:BI;
public function A(bInst:BI):void {
  this.bInst = bInst;
}


From this point, we've broken the dependency of A to B, and created a new dependency from A to BI. This is a better design and is more extensible: should we need to have different variations of B, as long as they implement the BI interface, A can utilize them.

What's more, 'FooBar' injected the dependencies into A.

That's all there is to it.

Now...my question is...how far can you take this??