0

I am working on an AutoCAD plugin. I have several methods that use

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database dataBase = doc.Database;
Editor editor = doc.Editor;

Would it be clean code to use those three lines at the beginning of my class and call doc, dataBase and editor whenever I need them or is it better to declare them in each method? It seems to save many lines of code but they kind of look like global variables which should be avoided as often as possible, right?

I've read several posts about global variables and fields but I can't seem to figure out whether or not I should use them that way.

Any thoughts on that are much appreciated.

  • 1
    I'm voting to close this question as off-topic because this question is better suited here imo, codereview.stackexchange.com – naveen Mar 03 '15 at 10:21
  • 1
    Class member != global variable. If you use it throughout your class, a class member is the logical choice. – CodeCaster Mar 03 '15 at 10:22

1 Answers1

1

Note AutoCAD is a multi-document application, therefore the active Document (including Editor and Database) will change from one command to another... that's why we get a fresh copy at the beginning of each command.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44