OO Design question

J

Jeff Louie

KJ...With .NET 2.0 you can implement delegation using generics!

using System;
using System.Collections.Generic;
using System.Text;

namespace GenericMI
{
// first we create the abstractions
public interface I1
{
void SayHello();
}
public interface I2
{
int GetValue();
}
public interface IProgram : I1, I2 { }

// second we write the concrete classes that implement the
abstractions
public class Implementation1 : I1
{
public void SayHello()
{
Console.WriteLine("Hello.");
}
}
public class Implementation2 : I2
{
private int i = 1;
public int GetValue()
{
return i;
}
}
// finally we write the wrapper class that contains
// the concrete classes
public class GenericMI<T1, T2> : IProgram where T1 : class, I1,
new()
where T2: class,I2, new()
{
private T1 pimplI1= new T1();
private T2 pimplI2 = new T2();
// we forward calls to the contained object
public void SayHello()
{
pimplI1.SayHello();
}
public int GetValue()
{
return pimplI2.GetValue();
}
}


class Program
{
static void Main(string[] args)
{
GenericMI<Implementation1,Implementation2> mi=
new GenericMI<Implementation1,Implementation2>();
mi.SayHello();
Console.WriteLine(mi.GetValue());
Console.ReadLine();
}
}
}

Regards,
Jeff
 
K

Kalpesh

Hi Everyone,

Although the discussion digressed a little, I got to see different view
points

Bruce, I liked your design :)
John - I will be reading the open-closed principle

I think, it requires great amount of understanding of domain (context),
before designing classes. So, making something base class, based on
common data - MIGHT not be a good idea.

Also, if I make address as part of BusinessEntity, it is kind of a
closed design
However, good discussion helps see different perspective

Thank you everyone & happy x'mas
Kalpesh
 
J

john_teague

Real Quick, paraphrased Open-Closed principle means "Open for
extensibility, closed for modifications" This means that if you need
to add functionality to a system you do it by writing new code and not
modifiy existing code. Making address part of BusinessEntity is the
opposite of what I'm talking about if there is different functionality
associated with address data.

Good Luck.
 
D

Dave Johnson

would u please show the Aggregation instead of inheritance in code.

you seem you have experiance doing it before which many coder and i am
one of them didnt encounter the need to do it yet.

would be very please to see any simple code explaining it

Thanks a lot

Sharing makes All the Difference
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Proper design of classes 8
OO + 3-Tier design Q 13
Basic OO question 5
Object design question 6
Advice on good OO design 3
Accesing property name at design times 4
Design question 1
OO design question 14

Top