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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:44:22+00:00 2026-06-05T01:44:22+00:00

Take this class for example: public class Account { public string Code { get;

  • 0

Take this class for example:

public class Account
{
    public string Code { get; set; }
    public string Description { get; set; }
    public DateTime CreatedOn { get; private set; }  

    public void Create()
    {
        // Invoke with new Account({...}).Create();
    }

    //Or

    public static void Create(Account account)
    {
        // Invoke with Account.Create(new Account({...}));
    }
}

Both Create() methods will both do the same thing, but as you can see they are invoked differently. Is one better practice over the other? Is there a term for writing code like this?

  • 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-06-05T01:44:24+00:00Added an answer on June 5, 2026 at 1:44 am

    In general, I don’t know that this is either good or bad practice. However, I would lean towards ‘bad practice’ in the example you have given (and I can’t off hand think of any useful reasons to pass an instance of a type to a static method declared on that type).

    Certainly in your example, you are (IMO) creating an unclear API. I’m not sure whether;

    • Account.Create is meant to issue data storage requests for an account (functionality that certainly belongs elsewhere in your object model)
    • is some sort of ‘convenience’ method for creating an instance of Account using some default set of parameters (which would arguably be better in a constructor of Account)
    • is meant as a copy constructor (in which case, it should be a constructor)
    • is a cheap implementation of an AccountFactory (in which case you should make a factory!)

    Another consideration is testing – static methods can introduce difficulties when unit testing anything that calls them, as they may not be easy to mock or stub.

    Apart from those, there is nothing inherently ‘wrong’ about this, technically. It affects your design in other ways though (e.g; no access to instance members as it is not an instance).

    So, I think this approach can lead to some confusion, however, it might also be entirely appropriate for your situation!

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

Sidebar

Related Questions

Take this example model: public class Location { public string Id { get; set;
Take a look at this code: public class Test { public static void main(String...
Take this class as example: public class Category : PersistentObject<int> { public virtual string
take this simple code: class A{ public: virtual void foo() = 0; void x(){
Take this simple example: class Program { static void Main(string[] args) { var windsorContainer
Take this sample class as an example: [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class BugFixAttribute : System.Attribute
I'm using SharedPreferences to persists Object fields. Take this example: class Item { private
Take this class for example: public class Applicant : UniClass<Applicant> { [Key] public int
Take this class for an example: <?php class Person { private $name = null;
Take my domain class for example public class Person { private Integer id; private

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.