Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 474631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:18:26+00:00 2026-05-13T00:18:26+00:00

Hello and thanks for any assistance. using .Net 3.5 C#; Say i have about

  • 0

Hello and thanks for any assistance.

using .Net 3.5 C#;

Say i have about 10 methods that all follow the same pattern

Using 3 as an example:

public Customer CreateCustomer(Customer c) { .. }
public Car CreateCar(Car c) { .. }
public Planet CreatePlanet(Planet p) { ..}

the internal logic of each method has the exact same pattern.

IE:

public Customer CreateCustomer(Customer c)
{
Log.BeginRequest(c, ActionType.Create); 
Validate(customer);
WebService.Send(Convert(c));
Log.EndRequest(c, ActionType.Create); 
}

public Car CreateCar(Car c)
{
Log.BeginRequest(c, ActionType.Create); 

Validate(c);

WebService.Send(Convert(c));

Log.EndRequest(c, ActionType.Create); 
}

The same is true with CreatePlanet and the other 7 methods.

Can these methods be re-written, they all follow the same pattern, and I feel like I am missing something… Is there is another level of abstraction that could be derived?

Question: How should this be re-written to take advantage of proper architecture pattens?

Thanks,
Steven

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:18:26+00:00Added an answer on May 13, 2026 at 12:18 am

    It seems like a case that fits the template pattern. You can make all of the entities implement the same interface/base and execute the action against the interface.

    I assume the only part that has to know the actual type is Validate(). It can be solved by two ways:

    1. Having the interface/base declare Validate and then implement it in each concrete entity.
    2. Define a strategy mapping between type of concrete entity and the actual validate strategy.

    Example using base class abstract validation –

    Base of entity, where it has internal service for create and abstract definition for validate:

    public abstract class EntityBase
    {
        protected abstract void Validate();
    
        protected void Create(EntityBase c)
        {
            Log.BeginRequest(c, ActionType.Create);
            c.Validate();
            WebService.Send(Convert(c));
            Log.EndRequest(c, ActionType.Create); 
        }
    }
    

    Concrete implementor with validate functionality:

    public class Customer : EntityBase
    {
        private int year;
    
        public Customer(int year)
        {
            this.year = year;
        }
    
        public void CreateCustomer(Customer c)
        {
            Create(c);
        }
    
        protected override void Validate()
        {
            if (year < 1900)
            {
                throw new Exception("Too old");
            }
        }
    }
    

    I didn’t see in the original code what Create returns so I changed it to void to make the example clear

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello all and thanks for any help in advance. I have a ruby on
Hello all and thanks for your time. I believe I have a simple question.
Hello All and thanks ahead for any help I'm working on a website which
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on
Hello I have test's using unittest. I have a test suite and I am
Hello and thanks in advance for taking a look at this. I have discovered
hello all, need to define a function that can be divided term by term
Hello and thanks in advance for any help you can provide. My AIR application
Hello and thanks for your time, I am creating an application that moves video
Hello and thanks for looking! Background I am designing a greenfield application using .NET4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.