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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:20:57+00:00 2026-05-13T16:20:57+00:00

I am designing a class library which will be used like this: Engine eng

  • 0

I am designing a class library which will be used like this:

 Engine  eng = new Engine();
 eng.AddPart(part).AddPart(otherPart).Run();

The problem with the class is that the parts are kept by the engine so if you want Run it with some other parts you will need to remove the ones that you have already added. There are several possible solutions but I am not sure which one is the best.

1.
Ignore it in class library, the users will call new every time they need to discard old parts.

2.
Automatically discard parts when Run is called

3.
Add Clear method

4.
Instead of returning current object from the AddPart method (return this) return new instance of Engine and do not modify the current one.

5.
Implement IDisposable so that the user can wrap it in using statement even though no resources are hold that need to be disposed. Users will use it like this:

  Engine eng = new Engine();
  using(eng)
  {
      eng.AddPart(part).Run();
  }

The disadvantage of the second one is that it users might need to reuse the same one and will not expect that parts are cleared. The third one is nice but users might forget to call Clear method. The fourth option will allocate many instances and the fifth one is unintuitive.

Any suggestions?

  • 1 1 Answer
  • 2 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-13T16:20:58+00:00Added an answer on May 13, 2026 at 4:20 pm

    The Clear() method is the most appropriate choice here; either that, or just require that the user create a new Engine. Clear() makes the behavior of your library most obvious.

    You could also consider overloading the Run() method to accept one or several Parts. This version of Run() would simply execute the parts, not hold onto them.

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

Sidebar

Related Questions

I'm designing an iOS static library that will be used by other developers. This
I am currently designing a class library that will provide data to a web
I am designing an API for a C++ library which will be distributed in
I'm designing a library that will be used to intercept and process incoming messages
I am designing a Framework library which can be used to store a hierarchically
I'm designing a class library that will be sent out to the public for
I have created a class library (assembly) that provides messaging, email and sms. This
I am designing a class library designed to solve a wide scope of problems.
I am designing the API for a Python library, and have run into a
I am in the process of designing a web application which will have multiple

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.