# OOP in Math

My coworker Lyubo came up with the following OOP problem while we were having lunch the other day. He says it is a well known problem that you can see on numerous places but it is new to me.

We know from mathematics that the square is a special case of rectangle. In OOP terms "special case" means inheritance. Obviously the mathematical square inherits from mathematical rectangle. Your task is to create OOP model for that relationship. Lets say that we want the rectangle to expose get property (getter for you Java readers) – the area of the rectangle. This is not as simple as it sounds. Here is one of the simplest (and very wrong) solutions:

class Rectangle
{
/// <summary>
/// A side of the rectangle
/// </summary>
public uint A { get; set; }

/// <summary>
/// B side of the rectangle
/// </summary>
public uint B { get; set; }

virtual public uint Area
{
get { return A * B; }
}
}

class Square : Rectangle
{
public override uint Area
{
get
{
return A * A;
}
}
}

However this means that the B property is not actually used. This can lead to unexpected results in polymorphic client code. We expect a rectangle to have a area of A*B and somehow it will not if it is an instance of Square. We can override the property setters, add some exceptions but what inheritance means is that the child class can do ANYTHING that the base class can. If you need to add special case behavior for any of the child classes then the inheritance hierarchy you have created is simply wrong. So go ahead make it right... (or view full text for explanation)
Tags:   english programming
Posted by:   Stilgar
00:20 25.10.2008

# User-friendly Oracle

I was trying to get Oracle JDeveloper 11g today but as always with Oracle products this proved to be quite a challenge...
Tags:   english stupid tech
Posted by:   Stilgar
03:54 22.10.2008

# The Man Who Taught Us the Way Football Should Be Played

Normally I do not write about sports and I do not really like football in particular. However the man I am gonna tell you about today is not your usual football legend. His name is Stanley Matthews and Pelé himself said about him:

"The man who taught us the way football should be played"

In my opinion this should be extended to sports in general because sports are not about physical shape and it is not about winning prizes. It is about human will, respect and friendship (that is why chess, motor-sports and e-sports are considered sports) and this man embodies the true spirit of sport.

Matthews was born on February 1st 1915. He signed professional terms with his hometown team Stoke City in 1932 and debuted for England in 1934. His last game for the national team was in 1957 at the age of 42 which makes him the oldest player to ever play for England. His last professional match in England was in 1965 at the age of 50. The same year he was knighted for services to sport and was the first ever football player to be knighted. He is also the only football player to be knighted while still playing. While we are at it in 1956 he received the first Golden Ball award. After that he moved to Malta to coach some team and he even played for them. Some reports state he played even in his 60s.

Except for showing formidable willpower and body shape Matthews was a real gentleman. This is best illustrated by the fact that for more than 700 league matches he was NEVER booked.

He died at the age of 85 and his ashes were buried beneath the central circle of  Stoke City's stadium. February 1st is an unofficial "Sir Stanley Matthews Day" on which staff in offices is encouraged to come to work dressed in football shirts.
Tags:   english
Posted by:   Stilgar
20:55 19.10.2008

# Dev Reach 2008

Here comes the report from Dev Reach 2008 that countless readers eagerly await. As you may know I am very fond of attending events like this so naturally I was quite excited. Most of the speakers were people whose blogs I had found multiple times when googling some .NET related problem but rest assured that the Bulgarian lecturers, albeit few, were on par with the famous foreigners...
Tags:   english events
Posted by:   Stilgar
05:06 17.10.2008

# Functional Sieve of Eratosthenes

I was thinking of how I can use functional constructs to implement Sieve of Eratosthenes and I bet that millions of readers are dying to learn what I came up with...
Tags:   english programming
Posted by:   Stilgar
01:07 13.10.2008