473,411 Members | 2,272 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,411 software developers and data experts.

Help with a pattern

Hi,

I have a problem with a pattern that has probably been solved a 1000
times before, but I'd appreciate some advice.

I have a scenario where I have a couple of data classes with getters
and setters called HTMLLink and DocumentLink classes, which are
extended from a LinkBase class. I'm wanting to pass these to a service
layer class which has a create method and carries out some business
logic depending on the object type passed in.

I'm in the position where I either have the HTMLLink and DocumentLink
classes with an implementation of the create method, or a big switch
statement in the service object. I'm not too keen on the link classes
having the create because they were supposed to be simple DTO style
objects. On the other hand I don't want a big switch statement in the
service either.

Is there any other way I can cut this? Thanks.

Jul 17 '06 #1
2 1153
"Spondishy" <sp*******@tiscali.co.uka écrit dans le message de news:
11**********************@b28g2000cwb.googlegroups. com...
| I have a scenario where I have a couple of data classes with getters
| and setters called HTMLLink and DocumentLink classes, which are
| extended from a LinkBase class. I'm wanting to pass these to a service
| layer class which has a create method and carries out some business
| logic depending on the object type passed in.
|
| I'm in the position where I either have the HTMLLink and DocumentLink
| classes with an implementation of the create method, or a big switch
| statement in the service object. I'm not too keen on the link classes
| having the create because they were supposed to be simple DTO style
| objects. On the other hand I don't want a big switch statement in the
| service either.

Separate creation and processing :

public class ServiceLayer
{
public static LinkBase CreateLink<linkT>() where linkT : LinkBase, new()
{
return new linkT();
}

public void ProcessLink(HTMLLink link)
{
...
}

public void ProcessLink(DocumentLink link)
{
...
}

...
}

....Or combined :

public class ServiceLayer
{
public void CreateAndProcessLink<linkT>() where linkT : LinkBase, new()
{
linkT link = new linkT();
ProcessLink(link);
}

private void ProcessLink(HTMLLink link)
{
...
}

private void ProcessLink(DocumentLink link)
{
...
}
...
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jul 17 '06 #2

Joanna Carter [TeamB] wrote:
"Spondishy" <sp*******@tiscali.co.uka écrit dans le message de news:
11**********************@b28g2000cwb.googlegroups. com...
| I have a scenario where I have a couple of data classes with getters
| and setters called HTMLLink and DocumentLink classes, which are
| extended from a LinkBase class. I'm wanting to pass these to a service
| layer class which has a create method and carries out some business
| logic depending on the object type passed in.
|
| I'm in the position where I either have the HTMLLink and DocumentLink
| classes with an implementation of the create method, or a big switch
| statement in the service object. I'm not too keen on the link classes
| having the create because they were supposed to be simple DTO style
| objects. On the other hand I don't want a big switch statement in the
| service either.

Separate creation and processing :

public class ServiceLayer
{
public static LinkBase CreateLink<linkT>() where linkT : LinkBase, new()
{
return new linkT();
}

public void ProcessLink(HTMLLink link)
{
...
}

public void ProcessLink(DocumentLink link)
{
...
}

...
}

...Or combined :

public class ServiceLayer
{
public void CreateAndProcessLink<linkT>() where linkT : LinkBase, new()
{
linkT link = new linkT();
ProcessLink(link);
}

private void ProcessLink(HTMLLink link)
{
...
}

private void ProcessLink(DocumentLink link)
{
...
}
...
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Thanks for the response, it's really appreciated... Unfortunately the
code doesn't appear to work. The ProcessLink method says it cannot
convert LinkT to DocumentLink?

Jul 17 '06 #3

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

Similar topics

7
by: Phil Powell | last post by:
I am having to use an existing FormValidator class to check form elements, and one of the things I must check is to see if someone entered tags in the string <>; if so, it must flag for that. ...
10
by: Case Nelson | last post by:
Hi there I've just been playing around with some python code and I've got a fun little optimization problem I could use some help with. Basically, the program needs to take in a random list of no...
6
by: kittykat | last post by:
Hello, I am writing a program that will read each line of a file into a vector of vectors. This data will then be analysed. Here is what i have done: typedef vector<string> lines; ......
4
by: system7designs | last post by:
I don't know preg's that well, can anyone tell me how to write a regular expression that will select everything BUT files/folders that begin with ._ or __?(that's period-underscore and underscore...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
4
by: =?Utf-8?B?bWFnZ2ll?= | last post by:
hi, I need some help with a reg. expression. I have a comma delimited file with quotes. Not every field has quotes, only some. This is a sample of my file:...
8
by: Martin Nadoll | last post by:
hello, i need a regular expression for my form-validation: it should be allowed to fill a <input type="text"with any iteger number up to 500 or a integer number up to 500 followed by px...
9
by: Simon Woods | last post by:
Hi I'm new to Regular Expressions so ... I trying to work out regular expressions to parse the following (a + (b + c)) I really want to replace it with
32
by: falconsx23 | last post by:
I am making a game called Set, it is a card game: here is a brief description of the rules: The game of Set is played with 81 cards, each of which has 4 properties (number, pattern, color and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.