spacer
Yehuda Shiran May 27, 2002
Using Qualified Names
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
You are always on the safe side when using qualified names, especially when you import namespaces. Why be surprised later with a name collision and unexpected behavior of your code? The following example demonstrates the need for qualified names. There are three imported namespaces, defined as follows:

  package USA {
     class Head {
       static var President : String = "Bush";
     }
  };
  
  package UK {
     public class Head {
        static var PrimeMinister : String = "Blair";
     }
     public class Localization {
       static var Currency : String = "Pound";
     }
  };

  package USA.Florida {
    public class Head {
      static var Governor : String = "Bush";
    }
  };
Let's declare a local class now:

  class Head {
    static var Governor : String = "Davis";
  }
Let's import the three databases from above:

  import USA;
  import UK;
  import USA.Florida;
And then let's print some class members:

  print(Head.Governor);
  print(USA.Head.President);
  print(UK.Head.PrimeMinister);
  print(USA.Florida.Head.Governor);
  print(Localization.Currency);
  print(UK.Localization.Currency);
Here is the output of the above code:

  Davis
  Bush
  Blair
  Bush
  Pound
  Pound
Notice that when the class location is ambiguous, you must use fully-qualified names. The class Head, for example, appears in USA, UK, USA.Florida, and locally, so the namespace must prefix this class. The class Localization, however, appears only in the UK namespace, so there is no need to use the fully-qualified variable names.

To learn more about JScript .NET, go to Column 109, JScript .NET, Part III: Classes and Namespaces.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags