473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Looking for a pattern to solve this problem;

Friday, no brain power remains...

I have three assemblies; Client, Interface and Implementation.

The Client uses Implementation through remoting.
Client has a reference to Interface, but not to Implementation. Likewise,
Implementation has a reference to Interface, but not to Client.

Interface contains a class that I want to be constructed by some
class+method in Implementation, and nowhere else.

I would make the constructor internal, but the constructing class+method is
in another assembly.

Here is a greatly simplified example;

== Client ==

using System;
using Interface;

namespace Client
{
class Class1
{
// <snip/>

[STAThread]
static void Main(string[] args)
{
string someurl = GetsInitializedSomehow();

IConstructSomeClass foo =
(IConstructSomeClass)Activator.GetObject(
typeof(IConstructSomeClass), someurl );

SomeClass some = foo.Construct( "This is a test" );
}
}
}

== Interface ==

using System;

namespace Interface
{
[Serializable]
public class SomeClass
{
// I want this constructor to be hidden
public SomeClass( string data ) {
this.data = data;
}

private string data;
public string Data
{
get { return data; }
}
}

public interface IConstructSomeClass
{
SomeClass Construct( string data );
}
}

== Implementation ==

using System;
using Interface;

namespace Implementation
{
public class Class1 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToLower() );
}
}

public class Class2 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToUpper() );
}
}
}
Nov 15 '05 #1
3 1827
Brad,

Maybe I am missing something, but why are you going to have the class in
the Interface assembly? Why not just place it in the Implementation
assembly? If the class is never going to be used anywhere but the
Implementation assembly, then I don't see the problem.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Brad Quinn" <br********@yahoo.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
Friday, no brain power remains...

I have three assemblies; Client, Interface and Implementation.

The Client uses Implementation through remoting.
Client has a reference to Interface, but not to Implementation. Likewise,
Implementation has a reference to Interface, but not to Client.

Interface contains a class that I want to be constructed by some
class+method in Implementation, and nowhere else.

I would make the constructor internal, but the constructing class+method is in another assembly.

Here is a greatly simplified example;

== Client ==

using System;
using Interface;

namespace Client
{
class Class1
{
// <snip/>

[STAThread]
static void Main(string[] args)
{
string someurl = GetsInitializedSomehow();

IConstructSomeClass foo =
(IConstructSomeClass)Activator.GetObject(
typeof(IConstructSomeClass), someurl );

SomeClass some = foo.Construct( "This is a test" );
}
}
}

== Interface ==

using System;

namespace Interface
{
[Serializable]
public class SomeClass
{
// I want this constructor to be hidden
public SomeClass( string data ) {
this.data = data;
}

private string data;
public string Data
{
get { return data; }
}
}

public interface IConstructSomeClass
{
SomeClass Construct( string data );
}
}

== Implementation ==

using System;
using Interface;

namespace Implementation
{
public class Class1 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToLower() );
}
}

public class Class2 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToUpper() );
}
}
}

Nov 15 '05 #2
My real client calls a method on a remote object. I'm using an interface
assembly to decouple the client and the remote object. The real method has
a few parameters and a complicated return type, hence the class in the
interface assembly.

The correct solution (I guess) is not to return a class, but rather an
interface that describes the class.

My real implementation contains the only objects with the "authority" (for
lack of a better word) to construct returned class. That is, the client
should not be able to instantiate the class returned by the remote object,
except by calling the remote object.

The incorrect solution that I was looking for was some kind of friend
functionality.

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Os*************@TK2MSFTNGP10.phx.gbl...
Brad,

Maybe I am missing something, but why are you going to have the class in the Interface assembly? Why not just place it in the Implementation
assembly? If the class is never going to be used anywhere but the
Implementation assembly, then I don't see the problem.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Brad Quinn" <br********@yahoo.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
Friday, no brain power remains...

I have three assemblies; Client, Interface and Implementation.

The Client uses Implementation through remoting.
Client has a reference to Interface, but not to Implementation. Likewise, Implementation has a reference to Interface, but not to Client.

Interface contains a class that I want to be constructed by some
class+method in Implementation, and nowhere else.

I would make the constructor internal, but the constructing class+method

is
in another assembly.

Here is a greatly simplified example;

== Client ==

using System;
using Interface;

namespace Client
{
class Class1
{
// <snip/>

[STAThread]
static void Main(string[] args)
{
string someurl = GetsInitializedSomehow();

IConstructSomeClass foo =
(IConstructSomeClass)Activator.GetObject(
typeof(IConstructSomeClass), someurl );

SomeClass some = foo.Construct( "This is a test" );
}
}
}

== Interface ==

using System;

namespace Interface
{
[Serializable]
public class SomeClass
{
// I want this constructor to be hidden
public SomeClass( string data ) {
this.data = data;
}

private string data;
public string Data
{
get { return data; }
}
}

public interface IConstructSomeClass
{
SomeClass Construct( string data );
}
}

== Implementation ==

using System;
using Interface;

namespace Implementation
{
public class Class1 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToLower() );
}
}

public class Class2 : MarshalByRefObject, IConstructSomeClass
{
public SomeClass Construct( string data )
{
return new SomeClass( data.ToUpper() );
}
}
}


Nov 15 '05 #3
I'm having some trouble making this work.

When my "Interface" assembly defines an interface, whose methods take
interfaces as parameters, neither the "Client" nor the "Implementation"
assembly is satisfied with just a reference to the "Interface" assembly.

Everything looks fine at compile time, but at runtime the "Client" and the
"Implementation" want to have access to the assemblies that actually
implement the interfaces.

In this case I may as well leave the class in the interface assembly. I
can't get things scoped the way I want them, but at least the assembly
dependencies are minimal.

"Brad Quinn" <br********@yahoo.com> wrote in message
news:uM**************@TK2MSFTNGP10.phx.gbl...
My real client calls a method on a remote object. I'm using an interface
assembly to decouple the client and the remote object. The real method has a few parameters and a complicated return type, hence the class in the
interface assembly.

The correct solution (I guess) is not to return a class, but rather an
interface that describes the class.

My real implementation contains the only objects with the "authority" (for
lack of a better word) to construct returned class. That is, the client
should not be able to instantiate the class returned by the remote object,
except by calling the remote object.

The incorrect solution that I was looking for was some kind of friend
functionality.

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:Os*************@TK2MSFTNGP10.phx.gbl...
Brad,

Maybe I am missing something, but why are you going to have the
class in
the Interface assembly? Why not just place it in the Implementation
assembly? If the class is never going to be used anywhere but the
Implementation assembly, then I don't see the problem.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Brad Quinn" <br********@yahoo.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
5
by: kittykat | last post by:
Hi again, Ok, i've solved my own problem, but now i have a tiny problem that i can't seem to solve. :( here's my code: #include <fstream> #include <string> #include <iostream> using namespace...
47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
6
by: Daniel Santa Cruz | last post by:
Hello all, I've been trying to go over my OO Patterns book, and I decided to try to implement them in Python this time around. I figured this would help me learn the language better. Well,...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
1
by: =?Utf-8?B?RXJpYw==?= | last post by:
I am using the factory method to solve a problem where a factory can produce product. I have a base factory class and a base product class. The problem that I am having is that for every product...
3
by: konrad Krupa | last post by:
This message is a continuation of my previous post "Pattern Match" Doug - Thank you for your help. Doug Semler was able to solve my problem to some point but I still need some help. Doug's...
11
by: George Sakkis | last post by:
I have a situation where one class can be customized with several orthogonal options. Currently this is implemented with (multiple) inheritance but this leads to combinatorial explosion of...
1
by: sunil | last post by:
Hello, I am working on a problem where I will have a boolean expression with upto four variables: A,B,C,D and connected by basic operator &&,||and may be XOR and NOT in future AND has higher...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.