Well, I don’t have much to say about the Refactoring: Change Bidirectional Association to Unidirectional (which is what I decided to look at this week on Monday). Sounds great! Change it if it makes sense.
Like Fowler says in the book, “The most difficult part of this refactoring is checking that I can do it.”
If the change will not cause too many ripple effects, it can be done very nicely. Otherwise, you may be facing a big ball of mud and it may not be feasible.
IBOutlets and Interface Builder
It has taken me about 5 sessions of working through the Pragmatic Programmers iPhone screencasts before I am starting to feel comfortable “wiring up” components through Interface Builder.
It really is a “visual” dependency injection framework. I specify the class that I want access to in my header file and optionally have properties set for it. Then, when I drag the visual representation of the class to another visual representation of another class, it tells the compiler to inject this class into that class.
Connecting, via the right click drag and drop, is essentially setting up a configuration that will inject that component into your class at runtime. Before today, I didn’t really notice the list of IBOutlets each component was expecting to have set and the list that each component was referenced by. For some reason, that was the point at which everything started to click.
Before today, I just saw Bill D. dragging stuff around and “wiring things together”. Then I would try to start from scratch without following him step by step and get totally lost as soon as I had to figure out which components to hook up to which controllers, etc.
I don’t know why it has helped me to think of it in terms of dependency injection, but if it helps, it helps. Probably more than anything, it just takes repetition until something clicks. One or two more episodes and possibly a small project start to finish, and I think it will be cemented in the brain paths for a good long time.
Pattern of the Week - Decorator
The intent of DECORATOR is to let you compose new variations of an operation at runtime. (Java Design Patterns)
The example given in the book identifies java streams as using the Decorator pattern. Right away my reaction is, I have always hated dealing with streams in Java, they are always so confusing.
I like Russ Olsen’s comment in Design Patterns in Ruby:
“The classic Decorator pattern is loved more by the folks who build the thing than by those who use it.”
I would agree.
But understanding Decorator will help me recognize when someone has chosen to use Decorator in an API, and maybe it won’t be confusing anymore.
When to use Decorator is not something I am going to try and explain. I am only interested in trying to explain what Decorator is, so as to help solidify it in my brain forever. I am going to give a short explanation and then a link to the code I have been experimenting with.
Once the class to be decorated (my example uses a Person class) has been determined, a suitable interface must be agreed upon, that all decorators must implement. The Decorator must take the Person class as a constructor parameter and delegate to that instance for all methods that it does not explicitly want to manage. In Most cases, the methods in the Decorator will always delegate to the person instance passed in but some methods will add additional logic.
This pattern allows chaining of Decorators and can be very flexible. Check out my ruby example code where in I experiment with Decorator following the Java idiom with its limitations and then using ruby modules. Notice how the two types of Decorators keep chaining together.
Git Hub Decorator.rb
Template Method and Strategy are competing patterns with Decorator.
Should I Trust the “Legion of the Bouncy Castle”
I love the idea of Java Web Start and have even given it another try recently (The New Webstart), but as an occasional user of Web Start applications, I can see why it will never take off. Java does not take off the engineering hats long enough to see how bad it really is.
Case Study:
SoapUI is a testing tool for web services that I have been using on a project. I needed to run only the GUI portion of SoapUI from my mac so I decided to just web start it and go from there.
The web start button on the web site looks fabulous, great job. I click on it and it asks me if I want to open the .jnlp file with Java Web Start. Sure, let’s do that.
First the ugly Java splash screen comes up. (-1)
After downloading all the SoapUI jars a popup asks me if I trust eviware? Sure, I click yes. Then I am asked if I trust sun micorsystems. Ok, i guess so, lets get on with this.
But the kicker was the last one which asked me:
“Do you trust ‘The Legion of the Bouncy Castle’?”
HUH???
So, I googled the legion and found out what it was, and it sounds legit. It is an open source encryption library of some kind. And great, if they want to call themselves that, but please do not ask the users of your software if they trust the Legion of the Bouncy Castle!
Do not ask me if I trust this application more than once, and never, never, never, never, never, never, never ask a USER if they trust the Legion of the Bouncy Castle!
(-1000)
I close the app after I am done and realize I have no way of opening SoapUI again unless I navigate back to the web site and relaunch it.
Web Start should make it hard for developers to leave the user hanging as to how to launch the app a second time.
(-5)
So I give that cumulative score of -1051
Using Sqlite3 in a Visual Studio 2008 C++ Application
I had a terrible time finding out how to get sqlite working with VC++ using the windows binaries from the sqlite download page. Most of the trouble was from me being a complete newb to VC++ but in the end I got it working. Here are the steps to follow along for next time.
- Download the precompiled binaries for Windows and also download the source code.
- The DLL download should contain the following files: sqlite3.dll and sqlite3.def
- The source code should contain lots of c code and header files, you need to find the sqlite3.h header file.
- Put sqlite3.dll, sqlite3.def, and sqlite3.h files into a directory somewhere.
- Next you need to create a sqlite3.lib file in order to implicitly link the dll to your project
- From the command line, navigate to the folder that has the sqlite3 files from step 4, then type the following:
- LIB /DEF:sqlite3.def
- This should create two more files: sqlite3.lib and sqlite3.exp
- NOTE: LIB.exe needs to be on your path and can be found it in the Visual Studio install directory (do a search).
- Now start a new console application project in Visual Studio
- Copy the sqlite3.dll, sqlite3.lib, and sqlite3.h files into your new project directory
- Right click on the Resource Files folder and choose Add >> Existing Item … then choose sqlite3.lib
- You may get a dialog that asks you about the custom rule, I just chose no.
- Now add the sqlite3.h file into your project headers directory in Visual Studio (project >> Add >> Existing item)
- Now you should be able to start using sqlite3: Here is a sample console app you can try.
- This will create a new db and a sample table and spit out a resultset to the console.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|