Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ALLCAPS · Oct 07, 2013 at 05:20 AM · c#monosharingencapsulation

What's the best way to hide classes when sharing C#?

I've made a cool thing, and I want to share cool thing. Said thing has many C# classes that make it work, and some of them have names like Face, Vertex, Model, and so on. Needless to say I don't want to muck up peoples namespaces with these. These classes will only be used inside of the thing I'm sharing, and there's only one class the user needs access to to make the whole show work. What's the best way to hide the others?

Should I put them all in a namespace, and just have the user "using CoolThing'" in the script they need to use the cool thing in? There will only ever be once of these in a scene, and therefore this will have to be done on exactly one script. (which I have included for them).

Is there an easier/better way to isolate my internal classes from the rest of the world?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Oct 07, 2013 at 01:14 PM

If you're developing a framework, meaning other people access your framework from a different assembly, the best way is to use the internal keyword.

If, for some reason you need to share the assembly with those other programmers, you can prevent polluting the global namespace unnecessarily and restrict access by other programmers by making all your not accessible classes nested private classes within the only public class. Sort of like a makeshift namespace (possibly within another namespace).

Consider the following:

 public class PublicClass : MonoBehaviour{
     
 private class HiddenClass{}
 
 private class NotAccessibleClass{
     HiddenClass h = new HiddenClass(); //works
 
 }
 }
 
 public class TestClass{
     PublicClass.NotAccessibleClass attempt; //compilation fail
 }

Only PublicClass will be visible to the End-User (MonoDevelop's IntelliSense will show the 'hidden' classes if you try the dot-notation on it). Everything else works internally like it should, assuming you don't need to inherit from MonoBehaviour and use Unity-functions in the nested classes.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by gjf · Oct 07, 2013 at 10:16 AM

even if you use your own namespace, there's still a chance for some confusion when referencing your objects, etc. versus unity's own.

ideally, you'd prefix yours with something to avoid that situation, along with its own namespace.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Support the MONO AOT Compilation on Android 0 Answers

Mono library to connect to Java/Python/Node backend? 1 Answer

Compatibility level and writing *.txt files 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges