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 915765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:56:33+00:00 2026-05-15T17:56:33+00:00

I want to customize a object’s behavior before the object is created. I think

  • 0

I want to customize a object’s behavior before the object is created. I think maybe add some hooks in the object constructor and do the change there would be a choice. Is there any way to do so in .net? Thanks a lot in advance!

EDIT:

Here is a example:

Assume we have a class Kid which use Perform method to get credit in the class.

public class Kid
{
    public void Perform() { ... }
}

And the School conduct to lectures:

public class School
{
    public void Chemistry() {
        // The school have a good chemistry teacher, so every kid study well
        // Kid.Perform() is modified to reflect that 
        Kid tom = new Kid();
        tom.Perform();
    }

    public void Biology() {
        //This class is boring, everyone will nap in 5~10 min
        // Kid.Perform() use a random number to simulate how 
        //long this kid can hold it.
        Kid tom = new Kid(); tom.Perform();
        Kid jerry = new Kid(); jerry.Perform();
    }
}

We want every kid perform in the same way and I do not want:

  1. Change class Kid because it is generated from a 3rd party tool and widely used somewhere else.
  2. Use inheritance.
  • 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-15T17:56:34+00:00Added an answer on May 15, 2026 at 5:56 pm

    In your case you would have to add your logic after calling the constructor. You could write a factory method which does this; replacing new SpecialObject() with MyExtendedSpecialObject.Create() shouldn’t be too difficult.

    public static class MyExtendedSpecialObject
    {
        public static SpecialObject Create()
        {
            var newObject = new SpecialObject();
    
            // Do something with newObject
    
            return newObject;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed Wix 3.5 and i want to customize some dialogs, where can
I want to customize std::vector class in order to use an OpenGL buffer object
How can I add a custom user variable for the user object? I want
I want to output my own object to a STL stream but with customized
My app works with the Devise gem for authentication, but I want customize it
I want to customize a .NET build process so that I can run an
I want to customize the parameter in createuser() method Membership Provider, Actually, i have
I want to customize ToolStripMenuItem by overriding OnPaint function. This is a MyToolStripMenuItem: public
I want to customize my own progress bar thru image view. I want to
I have mp3 catalog portal and I want to customize my urls. I used

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.