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

  • Home
  • SEARCH
  • 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 971767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:00:56+00:00 2026-05-16T03:00:56+00:00

Hello there freaks & geeks. Here comes my question again, thanks for helping!. Lets

  • 0

Hello there freaks & geeks. Here comes my question again, thanks for helping!.

Lets suppose i have an object Foo, which method foo() does about 100 lines.

foo()
{
…
qwert
yuiop
asdfg
zxcvb
nmhjk
…
}

If a developer wants to add some code to foo(), it can be easily done with inheritance, composing or a Decorator Pattern.

But in the case he wants to modify “one line” in the middle of the code (changing a property value, invoking a method before something…), whats the best way to do it?

foo2()
{
…
qwert
yuiop
ASDFG
zxcvb
nmhjk
…
}

The goal is to let the original developer to define a behavior without worriying about what others will modify/change.

The new developer should be able to change the object/method/property without retyping the code.

Inserting breaks or predefining steps with callbacks/listeners or dividing the code into smaller pieces is not the desired option, cause it involves the first developer, which is sleeping. 😛

What about a commit environment where the changes made to the object need a commit to apply?
foo() does normal, then foo2 just change the desired properties and make commit.

Any other alternatives?

Thanks!

  • 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-16T03:00:56+00:00Added an answer on May 16, 2026 at 3:00 am

    But in the case he wants to modify "one line" in the middle of the code (changing a property, invoking a new function before something…), decorator it is not an option.

    What do you think is the correct approach to achieve this?(modify 2 lines of 100 without retyping all)

    Retyping the lines of code is not the issue, because the chances are it will be just a copy&paste. You need to eliminate code duplication. So make you function overrideable (so the next developer can inherit from it or extend it), and factor out all the common code into smaller separate functions.

    If you are using .Net then you could also consider refactoring the function to accept a delegate or lambda as one of its parameters, and that delegate/lambda gets executed at the critical spot (this may be your best option). You may also be able to achieve your aim with partial classes – you write some of the code of the class, the other developer writes the rest, although this may be a messy solution for your problem.

    Should i design a() with 100 listeners/callbacks? Should i define some "known steps" and use something like "insertCodeBefore/After(step)"?

    This is likely to also be a very messy and inefficient solution.

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

Sidebar

Related Questions

Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello there I have a database that has 2 tables in it, one is
hello there and sorry for the stupid question but i think i might be
Hello there and Merry Christmas !!! I am new to WPF and I am
Is there the equivalent of the Hello World program for GIS applications? I am
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello can anybody solve this please I'm creating the object in the action class
Hello there fellow Stackers! I wonder if anybody could tell me what the following
hello there is something i've realized with quartz when working.Say a cron is set
Hello there I am working on an assignment in C where I need to

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.