Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Some advise on the following code

Some advise on the following code

Scheduled Pinned Locked Moved C#
regexquestionworkspace
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venomation
    wrote on last edited by
    #1

    Hello I have the "following" code:

    controller = Controller.BuildSingleRow(_sheet);

    _animator = Animator
    .WithStartupInfo(_controller, PlayMode.Normal, 1f);

    I have used a static method in the Controller class to setup some method of build pattern, I was going to use a constructor but a static instantiation won it for me. Is this bad to do this? Thanks :-D

    P M B 3 Replies Last reply
    0
    • V venomation

      Hello I have the "following" code:

      controller = Controller.BuildSingleRow(_sheet);

      _animator = Animator
      .WithStartupInfo(_controller, PlayMode.Normal, 1f);

      I have used a static method in the Controller class to setup some method of build pattern, I was going to use a constructor but a static instantiation won it for me. Is this bad to do this? Thanks :-D

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Seems OK, depends on the usage.

      1 Reply Last reply
      0
      • V venomation

        Hello I have the "following" code:

        controller = Controller.BuildSingleRow(_sheet);

        _animator = Animator
        .WithStartupInfo(_controller, PlayMode.Normal, 1f);

        I have used a static method in the Controller class to setup some method of build pattern, I was going to use a constructor but a static instantiation won it for me. Is this bad to do this? Thanks :-D

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Read up on static constructors [^]

        Never underestimate the power of human stupidity RAH

        V 1 Reply Last reply
        0
        • M Mycroft Holmes

          Read up on static constructors [^]

          Never underestimate the power of human stupidity RAH

          V Offline
          V Offline
          venomation
          wrote on last edited by
          #4

          I read through it and I can see how that would be useful however "perform a particular action that needs performed once only", I intended those methods to be used more than once and to increase the usability of the code. So when people see:

          Controller.BuildSingleRow(_sheet);

          They realise that it constructs the object set to a single row sprite sheet... It seems ok to me but im sure there is someone out there who would slap me in the face... :laugh:

          P 1 Reply Last reply
          0
          • V venomation

            I read through it and I can see how that would be useful however "perform a particular action that needs performed once only", I intended those methods to be used more than once and to increase the usability of the code. So when people see:

            Controller.BuildSingleRow(_sheet);

            They realise that it constructs the object set to a single row sprite sheet... It seems ok to me but im sure there is someone out there who would slap me in the face... :laugh:

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            It seems related to the Abstract Factory and Factory Method Design Patterns, but not as complex.

            1 Reply Last reply
            0
            • V venomation

              Hello I have the "following" code:

              controller = Controller.BuildSingleRow(_sheet);

              _animator = Animator
              .WithStartupInfo(_controller, PlayMode.Normal, 1f);

              I have used a static method in the Controller class to setup some method of build pattern, I was going to use a constructor but a static instantiation won it for me. Is this bad to do this? Thanks :-D

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              It is not bad if there is a good reason why the 'constructor' shouldn't actually be a constructor in language terms. For example, if Controller is a pseudo-factory class that can actually build several different final classes in these methods, or the build methods need differentiation by name for clarity. If this is the only 'BuildXxx' method and it returns an instance of Controller, it should be a constructor (and the class should probably be named with the 'single row' aspect) – after all, that's what a constructor is, a static method that returns a new instance of the class, and people expect to instantiate classes that way. One small point to bear in mind is that any sort of reflection-based instantiation is not likely to find your static method. You may well not be doing any of that though.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups