Blug Factory

Saturday, March 04, 2006

Takahashi Method

Very interesting Presentation method.

How to create Takahashi Method presentation in XUL.

Was inspired by Jim Weirich’s RubyOnRails presentation, Jim Wienrich's blog , thanks Jim.

Here's a good example of the Takahashi Method with good info on
Identity management.

Web Identity 2.0

Talk on Web Identity.

Identity 2.0 Video

Web Identity 1.0 = Each site is an identity silo, (Amazon, Google,..). Each having it's own concept and storage of you're identity. Usually username/password. These create walled gardens.

Web Identity 2.0 = Trusted source, (Certificate Authority, State of Mass,..), gives you credential, (Client Certificate, Drivers License), that's accepted by gatekeepers, (Web Sites, Liquor Store clerks), to give you access to resources, (Web Accounts, booze).

Identity 2.0:
  • Scales well, keep Trusted source out of authorization process.
  • Preserves privacy, trusted source not aware of accessing resources.
  • Needed for web services because they cross walled gardens of identity silos.

Sounds like client side certificates to me?

BTW, this presentation style is called the "Takahashi Method"

Monday, January 09, 2006

More Anemic Domain Models.

Last month I posted about anemic domain models . Here are some more thoughts, hopefully clarifications with an example that shows the problem and the solution using new features in Spring 2.0.

Get a Customer's credit score using a remote credit score service.

- I need a Customer entity, entity = persisted instance, that was previously persisted in theDB. I'll call a DAO's find method to get this entity. The DAO is implemented using hibernate.

// use hibernate to find and re-constitute the customer from the DB
Customer customer = customerDAO.find(33);

- Get the customer's credit score. This will make the remote call to get the score.
int creditScore = customer.getCreditScore().

- The Customer's getCreditScore() method is implemented such that it needs to do a remote call to a CreditAgency to get the creditScore. Customer DEPENDS on CreditAgency.

public class Customer {
// identifies this customer at the credit agency
long customerNumberAtCreditAgency;
// Collaborator
CreditAgency creditAgency;

// setter for CreditAgency, this is where the dependency should be injected.
public void setCreditAgency(CreditAgency ca){
creditAgency = ca;
// make a remote call to get this customer's score.
public int getCreditScore(){
// do the remote call.
return creditAgency.getScore(customerNumberAtCreditAgency);

- the CreditAgency class is an interface that has it's implementation injected into the Customer
instance using Spring. Another words, the Customer's has a dependency, CreditAgency, that is injected into it when it's instaniated.


The DAO is using Hibernate to instaniate, actually re-constitute from the DB, the Customer. I can't have the CreditAgency implementation injected into this Customer instance because Spring isn't creating the object.

Spring won't inject dependencies if it doesn't create the object. (May be able to use Hibernate Interceptors??)

Use Spring 2.0 to inject dependencies AFTER the Customer object is created.

Annotate the customer class.
import org.springframework.beans.factory.aspectj.SpringConfigured;

public class Customer {

- Add aspect to the bean config and set the customer bean so
that it doesn't get created by Spring at startup.

<!-- Add the following to the bean config xml.-->
< aop:spring-configured/>

< bean id="customer">
<property name="creditAgency" ref="creditAgency" />
</bean >

I don't really like how the annotation is being put into the customer class. I'd prefer to select which beans are configured in the xml config file.

Tuesday, December 13, 2005

CRUD for domain objects.

Where to put a domain objects CRUD operations?

Two possible ways:
- Move a domain object's CRUD operations into class methods of the domain object. Kinda like ActiveRecord used in Rails. For example:

Product p = Product.find_first(productName); // get a product obj
// get the employee pricing strategy
PricingStrategy employeePricingStrategy = new EmployPricingStrategy();
// calc the employee price for the product.
// change product's price

- Move domain object's CRUD method into a Repository, aka Domain Driven Design.

Monday, December 12, 2005

TSE, Anemic Domain Models.

A major theme of The Springframework Experience(TSE) was how to deal with Anemic Domain Models. Rod Johnson talked about how he met with Martin Fowler and Eric Evans and discussed this problem. Eric's book, Domain Driven Design, and Martin's book, PoEA, are must reads. And I've noticed many of Eric's ideas and patterns and language used at TSE presentations.

Below is my description based on what I've heard at TSE last week and gathered from Craig Wall's blog. Craig has an description of the problem and solution. After some considerable reflection, probably not the best example of when to use the new dependency injection features.

An Anemic Domain Model is where a design can degenerate to a set of procedures that implement most of the business, domain, logic. These procedures are implemented as methods in "Manager" singletons in the service layer. BTW, Manager may not be the best name. Not exactly an "Intention Relvealing Interface" as described in Domain Driven Design.

These Managers in the service layer have DAOs that are injected into it by Spring. And the DAO's create anemic domain objects that have little or no business logic and only contain data. The manager/service methods use the DAO and anemic domain objects while implementing business logic.

The problem described below is usually handled by lazy initialization with Hibernate. After some thought this is probably not the best example of when to inject dependencies into an object after creation. Perhaps a better example would be to inject behavior using the Strategy pattern. Gotta give Chris credit for a try soo soon, hours, after the feature was presented.

Following correct OO principles we should move the business logic into the business domain class. Then the business logic implemented in a domain object method could create/read/update/update any of it's collaboraters needed to complete it's business logic.

The current problem is that domain objects are not created by Spring, they are created by a persistence layer using Hibernate, JDBC, etc. Therefore, the domain objects can't have their collaborators/dependency DAO's injected. And you can't implement business logic if you can't perform crud on the collaborators needed by the logic!

To address this problem Spring 2.0 will be able to inject depenencies into an object after instantiation. Even if hasn't been created by Spring. This is done with Aspects. See Craig's blog for how this is done.

Warning, this is only implemented starting in Spring 2.0M1.

Check out this thread from the Spring Forum about this subject.

Spring, getting a new dependency instance for singletons.

I have a singleton bean that needs a new instance of a dependency everytime it calls the dependency's get method, getDependency() .

Use lookup-method injection. See pg 115 of Pro Spring for full story.

- Create an abstract class for you're singleton.
- Create a abstract getter in the singleton class.
public abstract class MySingleton{
public abstract MyDependency getMyDependency();

- Create the dependency bean config.
< bean id="mydependency" class="MyDependency" singleton="false" > < /bean >

- Create the bean configuration for the singleton.
< bean id="mysingleton" class="MySingleton">
<lookup-method name="getMyDependency" bean="mydepenency">

Now, whenever I get the dependency using the getMyDependency() method a new instance of MyDependency will be returned.

Warning: using this getter is expensive.

Sunday, December 11, 2005

The Spring Experience (TSE)

Attended the Spring Experience in Miami last week. Definitely was a learning experience. Got lot's to think about and digest.

The weather was perfect, 85 degrees. Altough, I didn't get to enjoy it that much with days ranging up to 13/14 hours of presentations and BOFs.

My general impressions where that the Spring Community is definitely growing, although not as fast as I've wished or hoped. I started with Spring in the fall of 03 and thought it'd be at least as big as Struts by now. Hard to understand why such a great technology isn't more widely adapted. Guess, I haven't realized the full power of the "other" forces in software development.

Bumped into Rick Hightower and hung out with'm for awhile. Good to see Rick, another top J2EE developer/author and consultant and positively the best instructor/training I've ever attended. He told me how he was on the beach when a conference attendee rescued some guy flailing in the Atlantic. Had some fun talking about how we fell into software.

Slid into a group conversation with Stuart Halloway, who wrote the most hidden treasure of Java. Stu was really excited about Ruby and Rails and was just railing about all the good stuff Ruby lets you do. I don't need any convincing but it was good to see someone I respect getting excited about Ruby.

Believe Stu said Revelence, Stu and Justin Gethland, where going to do some Rails/Ajax training. I've seen both of guys speak a number of times and they are excellent. They'll make it worth it.

At Thursday lunch I landed at a table where most where from Boston area. Guy next to me was just about up the road from me. Mike Clark, who I met a nofluff in Boston awhile back, was at the table. Mike's another major Spring fanatic. Got me thinking about a Spring user's group in Boston? Asked Rod Johnson about it and he said some guy in Australia might be setting up a group.

Also, sheepishly, asked the expert panel what Spring/Rails could learn from each other. Suprisingly, no one threw chewed food at me and Rob Harrod talked about how Spring MVC could establish some Rails like conventions. And Justin Gehtland talked about how Ruby's dynamic nature enables alot of the great Rails features.

Spent the other 2 days at the conference in a sleep deprived state try to stuff as much as possible into the head. My favorite sessions where the Justin Gehtland/(Mule,ESB), Keith Donald/Webflow, Bram Smeets/AJAX, Ben Alex/Acegi, Rod Johnson/Spring Testing. Altough 80% of the presentations I attended where just great.

At least I did get down to South Beach to hang out for couple of hours. Very cool place.

I'm intending on blogging in more detail over the next few days. Otherwise, I'll sleep ;-}

Tuesday, November 22, 2005

Rails Migrations.

Rails migrations allows you to version the changes to your DB schema. You'll need, at least, version 0. 14.3.

Check the rails version

rails --version
gem list rails

Here's an example that will create a task table

  1. Create the first migration to add a task table. This will create a migration in db/migrate/1_add_task_table.rb
    1. ruby script/generate migration add_task_table

  2. Add code to create and drop a the task table in the migration, 1_add_task_table.rb. Here are the methods that can be used to for migrations.

    1. class AddTaskTable < ActiveRecord::Migration
      def self.up
      create_table :tasks do |t|
      t.column :name, :string
      t.column :description, :string
      t.column :due, :datetime

      def self.down
      drop_table :tasks

  3. Run/Apply the migration
    1. rake migrate

Roll back DB migrations

Notice that each migration is created with a numbered prefix, 1_add_task_table.rb. To roll back migration changes you'll execute a versioned migration. For example, to roll back the DB to changes only made by the first three migrations:
rake migrate VERSION=3
This will invoke all the self.down methods in migrations greater than three.

Creating an existing schema

Also, you can generate the migration code needed to create an existing DB schema.
  1. You need to point rails at you're current DB by changing the /config/database.yml.

  2. Generate the migration code for the existing schema. This will create a /db/schema.rb file that contains the migration code.
    1. rake db_schema_dump.

  3. Create an initial migration for this schema.
    1. ruby script/generate migration intial_create

  4. Then you copy the code from schema.rb into a migration, /db/migrate/1_intial_create.rb.

  5. Run the migration to create the initial schema.
    1. rake migrate

Recommend Pragmatic Studio Rails training.

I would highly recommend the Pragmatic Studio Rails training. I attending the first incarnation of this training last week in Reston, VA. Excellent!

Mike Clark and Dave Thomas put together an great overview of Ruby and Rails. It does move very fast and it will take some time to assimilate all of the info. I found that they presented hard to find and difficult to grasp info on Rails in a clear and concise way.

I've seen both Mike and Dave present before, mostly at nofluff, and I've always learned something useful.

Really enjoyed their passion and excitement for our craft.

Thursday, November 10, 2005

Ajax App Builder IDE, Morfik

Joined the "Pioneer Program" for Morfik to get a look at their Ajax/WebOS application builder tool, WebOS App Builder. Ran through their video demo, actual app won't be out until next month, Dec 05.

Looks like a RAD tool for building Ajax apps. Has a visual dev environment for creating:
  • DB schema and SQL.
    • How limiting is the generated SQL?
  • Presentation with GUI builder. Can write GUI component event handlers in Morphic languages Java, VB, Pascal,...
    • Wonder what subset of these languages are supported?
    • Wonder what the generated HTML/JavaScript looks like? Burned by generated code alot.
    • Generates HTML/Javascript from Morphic languages.
    • Develop in typed Morphic OO languages to generate Javascript.
  • Report Designer that can generate PDFs.
You can create domain/application modules in any of the Morphic languages. These modules will also be compiled into HTML/Javascript

Looks likes the App builder also provides hooks to web services. Not sure how, or what the limitiations, REST/SOAP, are?

The App build generates an executable that contains:
  • Your Data model is implemented in an Embedded DB server, Firebird .
  • HTML/Javascript that will implement you're app.
    • Would like to know more about the runtime engine?
  • A web server.

At first glance the App builder looks like RAD tools I've seen for MS Access/VB. Not sure if or how it would integrate with with J2EE/.Net/Rails?

Thanks to the Ajaxian for pointing me towards Morphic