[Mono-list] Compiling egg-chicken libraries
Jaroslaw Kowalski
jaak@zd.com.pl
Thu, 26 Feb 2004 20:45:37 +0100
This is a killer problem. The actual code from "Objects" is here. I don't
want to pollute it with any unnecessary patterns. No factories, adaptors,
facades.
BTW. Some stubs return instances of business objects. This doesn't look
possible in your case.
=================
namespace Sooda.UnitTests.Objects
{
using System;
using System.Collections;
using System.Diagnostics;
using System.Data;
using Sooda;
public class Contact : Sooda.UnitTests.Objects.Stubs.Contact_Stub
{
public Contact(SoodaTransaction transaction) :
base(transaction)
{
}
public Contact() :
this(SoodaTransaction.ActiveTransaction)
{
}
public void SomeBusinessMethod()
{
if (PrimaryGroup.Manager.Name.StartsWith("John"))
{
Console.WriteLine("Hello John's employee!");
if (Roles.Contains(Role.Clerk))
{
Console.WriteLine("How are you?");
}
}
}
}
}
========================
The design is ugly, but makes such a simple syntax possible.
Jarek
----- Original Message -----
From: "Stuart Ballard" <sballard@netreach.com>
To: "Jaroslaw Kowalski" <jaak@zd.com.pl>
Cc: <aranym@adelphia.net>; <mono-list@lists.ximian.com>
Sent: Thursday, February 26, 2004 8:41 PM
Subject: Re: [Mono-list] Compiling egg-chicken libraries
> Jaroslaw Kowalski wrote:
> > I need (as an option) this for my O/R mapping software because I want to
be
> > able to use mutliple languages.
> >
> > I have:
> >
> > 1. "Stubs" assembly - written in C# - that must be able to create
objects
> > from "Objects" assembly to represent 1-1 relations and 1-N relations.
> > 2. "Objects" assembly - written in some other language whose classes
inherit
> > from the appropriate classes in "Stubs" assembly
> >
> > So I have a mutual dependency here. But as I've said this is optional.
If
> > you stict to C# you have just a single assembly with no
interdependencies.
>
> Sounds like what you need is an IObjectCreator interface, defined in
> Stubs and implemented in Objects.
>
> eg, in the Stubs assembly:
>
> public interface IObjectCreator {
> object CreateObject();
> }
> public class FooStub {
> IObjectCreator ioc;
>
> void Twiddle() {
> object o = ioc.CreateObject();
> // do something with o
> }
> }
>
>
> in the Objects assembly:
>
> public class Foo : FooStub {
> class FooCreator : IObjectCreator {
> public object CreateObject() {return new Foo();}
> }
> public Foo() {
> ioc = new FooCreator();
> }
> }
>
> The only problem is the need to explicitly define FooCreator for each
> class by hand. Depending on your circumstances, that may or may not be a
> killer problem.
>
> Stuart.
>
> --
> Stuart Ballard, Senior Web Developer
> NetReach, Inc.
> (215) 283-2300, ext. 126
> http://www.netreach.com/
>