13 Jun 2007, 11:11pm
Uncategorized:
by toni

leave a comment

4 things about domain objects

First, please do not mock a domain object. Stub it. Thanks.

Second, do not write an interface for it. Neither if you want a Null Object implementation.

Third do not be obsessed with Null Objects, sometimes they are good, not always. If you end with a

if objectInstanceType == ObjectType.NULL in your code perhaps something is wrong in your design, a null object is to avoid that stuff and to give a “null behaviour”.

Forth. Do not use the ActiveRecord pattern, seriously, you’re gonna couple the infrastructure layer with the domain layer. It’s not a pattern IMHO, kind of antipattern, try considering a repository.

Fifth. For the point one maybe you will like a builder pattern in order to stub objects. Here an example:

class PersonBuilder
{
private string name = "testname";
private int age;
public PersonBuilder Name(string value)
{
name = value;
return this;
}
}
public PersonBuilder Age(int value)
{
age = value;
return this;
}
public Person ToPerson()
{
return new Person(name, age);
}

Syntax then is nice, I really like it.

Person expected = new PersonBuilder().Age(29).Name(“antonio”).ToPerson();

and it encourages to write not mutable object like this Person:

class Person
{
private readonly int age;
private readonly string name;
public Person(string name, int age){…}
public int age
{
get { return age; }
}
}

Looks like I’ve lost my code formatter… :-(

10 Jun 2007, 8:13pm
Uncategorized:
by toni

leave a comment

.net infected

Day by day I’m always more .net infected, today I’ve found 4 good links. One is DZone which provides good quality links every day. From here I found this where the author tries to convince the reader that Java 6.0 has something cool and new inside… Bah!

Through the good mailing list on Yahoo about Domain Driven Development I’ve read this article about using LINQ, DDD and so on with .net, indeed.

And while writing the post, always through DZone I see that JRuby 1.0 is out.

So more than a .net infection maybe is a Java depression.

24 May 2007, 12:15am
Uncategorized:
by toni

3 comments

C#

C# is not so bad. It’s 7 weeks now that I am working with this language and I quite enjoy it.

The tool is terrible slash horrible, we are using resharper that helps a bit but it’s not comparable to any java IDE that I know. Just the UI designer is nice and pretty easy to use, Windows Forms are for sure better than Swing, that was kind of easy.

Talking about the syntax I really like the using syntax:

writing something like:

using(Session s = manager.GetSession())

{

DoSomething();

}

is equivalent to the java

Session s;
try {

s = manager.GetSession();

doSomething();

} finally { s.dispose();}
To put an object in the using () this object must implement IDisposable, and then implement the Dispose Method. Isn’t nice?

Then also all the event and delegate stuff, too lazy to explain, try to have a look here or search with Google!
Transaction to C# was kind of easy, in 2 weeks I was up to speed. I am looking forward to the next C#, it looks just amazing. Java where are you?