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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:35:12+00:00 2026-05-23T14:35:12+00:00

I have a class that requires some of its methods to be called in

  • 0

I have a class that requires some of its methods to be called in a specific order. If these methods are called out of order then the object will stop working correctly. There are a few asserts in the methods to ensure that the object is in a valid state. What naming conventions could I use to communicate to the next person to read the code that these methods need to be called in a specific order?

It would be possible to turn this into one huge method, but huge methods are a great way to create problems. (There are a 2 methods than can trigger this sequence so 1 huge method would also result in duplication.)

It would be possible to write comments that explain that the methods need to be called in order but comments are less useful then clearly named methods.

Any suggestions?

  • 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-23T14:35:12+00:00Added an answer on May 23, 2026 at 2:35 pm

    Is it possible to refactor so (at least some of) the state from the first function is passed as a paramter to the second function, then it’s impossible to avoid?

    Otherwise, if you have comments and asserts, you’re doing quite well.

    However, “It would be possible to turn this into one huge method” makes it sound like the outside code doesn’t need to access the intermediate state in any way. If so, why not just make one public method, which calls several private methods successively? Something like:

    FroblicateWeazel() {
       // Need to be in this order:
       FroblicateWeazel_Init();
       FroblicateWeazel_PerformCals();
       FroblicateWeazel_OutputCalcs();
       FroblicateWeazel_Cleanup();
    }
    

    That’s not perfect, but if the order is centralised to that one function, it’s fairly easy to see what order they should come in.

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

Sidebar

Related Questions

I have a class that requires a specific method to be called before being
I have a class that requires dynamically setting a List. I also call this
Let's say I have a class that requires configuration, dependency injection etc. public class
I have a class that executes the MSNP15 protocol. The protocol requires clients to
I have a web service client that has an Authenticator class. The Authenticator requires
I have an object of class Level that has several subsystems (child objects) it
Lets say I have a class that is supposed to generate some ID (for
I have the following partial methods in my partial class that is attached to
I have a module called user_searches. It performs some searches that aren't core to
I have a class called ExcelManager that is responsible for taking a path 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.