Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Single Responsibility Concern

Discussion in 'Scripting' started by TenBitNet, Feb 15, 2019.

  1. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    Since im using unity and trying to follow single responsibility principle. I have a issue where I have several scripts. Since I put these scripts into a template so the designer has a easier time placing it on objects.
    I have an issue where a template script needs to add every component of the script. The template script needs the data so the add scripts carry their respective data.This heavily couples the code to the template. Meaning if I ever add a new component or a component needs a new piece of data. Then I must add this information to the template script.
    Is there a way the the template script just has a list of monobehaviours that add themselves? How would I make them visible in the inspector?

    Edit: I have a decoupling issue. I believe if I just use the command pattern I can just rely on require component.
     
    Last edited: Feb 16, 2019
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    You're speaking a lot of theory here... and you hide your actual question in the middle of it without any punctuation signaling your actual question.

    I assume this is your question.

    And from a theoretical/logical perspective, sure, this is possible.

    As to how easily it will fit into your design is beyond me since well... we don't know what your template system is or how it's designed.

    How about get a little more specific... show us how your stuff, let us see what your templating system is.

    And the big one... instead of explaining how you did something, how about explain what it is you're attempting to accomplish.

    ...

    Imagine if I said "I'm driving my car through town X taking a left turn onto Main st, and then a right on Elm st, and I want to know if I can take a short cut on Cherry Rd?"

    When really all I want to know is "What is the shortest route to the grocery store from Main st in town X?"
     
    Joe-Censored likes this.
  3. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    Sorry I realize the problem now. i was too reliant on coupling everything. At the beginning of the project I didn't understand decoupling. Now that I've learned more I realize I can go back to relying on require component.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Yep, punctuation would make a much easier to read, appreciating time of the reader, and its purpose is, to better convey message. Putting comma in wrong place, can even change meaning of the sentence. Not putting at all, leaves ambiguity.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Not exactly sure what you're asking, but your scripts can certainly have lists of components, and can add them using yourObject.AddComponent<ComponentType>() and then set whatever properties you want after adding them. Not sure if that is what you're getting at, because you have the longest run on sentence I've ever seen outside of elementary school. Use periods, commas, etc. Also explain more what you are trying to do, rather than what you've done to reach some unmentioned goal.
     
  6. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    Sorry that my sentences were so incoherent for everyone. I went through everything and fixed it. Again sorry for the inconvenience!
     
  7. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,992
    "Single Responsibility" is about the S in SOLID? I wouldn't take it too seriously. It was made up at least 10 years after everyone was doing things that way, and isn't a very good explanation.

    When you're making a class, it's easy to keep growing it a little at a time, until it does everything. At some point, think for 15 seconds whether the new thing should be a separate class or a plug-in. If you're not sure, don't worry about it, but sometimes you immediately realize.