@Anonymous wrote:
You should probably read up on static verses instance members.
The code you show creates an instance of one class
(API_ForClass5), and calls a static API of that class, to
get an instance of another class (Class5).
You don't need to create an instance of a class to use
a static API of that class.
About your question, 'internal' visiblity means that a
member or class is visible to any code in the same
assembly, so if those two classes are in the same
assembly, it works.
My suggestion for anyone that's just starting out with the
AutoCAD managed API, is that they try to focus more on
the basic concepts of the language/runtime, like scope
and visiblity as they relate to 'static', 'internal' and so on
(the 'horse'), before trying to learn the AutoCAD managed
API (the 'cart').
@Anonymous
I see my code snippet has caused some confusion. I think the OP finally understood what it trying to illustrate. The intent was to demonstrate one way the code pattern for obtaining an instance of the Editor might look. What clases could like to force the consumer to reference a property in another class just ot obtain an instance of another.
I only mentioned Singleton because it is what I would have implemented internally, not wanting to rely on every one on the developer team being on the same page when it came to "Rules of Engagement" for the use of Class5. Someone might forget that only instance should exist throughout the lifetime of another object.
@Anonymous:
Congratulations on "getting it", as you put it. The code snippet that I posted---and which you re-posted---is a bit subtle and is not a true Singleton as Tony had pointed out. Just to be clear, here is what my intent was.
The first two classes would appear in an "API Assembly", while the 3rd class would be code written by a consumer like you the developer. Consumers cannot create instances of Class5. Any Class5 instance is created internally by the types defined within the API. So, a true Singleton is not needed. Although it wouldn't hurt to create one just in case.
In most cases, a Singleton is a self-contained class. The only instances are created are by Singleton class itself. My code snippet uses some "other class" to create instances, which are assigned to a static property witin the class.
If were writing the code, I would not allow consumers to create instances of this "other class" at all. I would have Factory Methods and/or Abstract Object Factory classes---the other class mentioned above---to set up and initialize the rather complex type, Application. You can read more about Object Factories, the GoF, and other OOP basics here.
http://www.dofactory.com/Patterns/Patterns.aspx
Rudy