3 Replies Latest reply on May 21, 2007 7:53 AM by kglad

    Namespaces

    hciguy Level 1
      Hi all,

      I know I am asking alot of probably rudimentary questions these days...I apologize in advance. My question this time: why use namespaces? What is their real purpose? I don't see a great difference between using a namespace and say just making a function or something...

      If you know a good article on namespaces I'd appreciate it too. I'm not familiar with them and their use. I understand how to define them and the like but trying to wrap my mind around their exact usage.

      Thanks for all the help in advance!
        • 1. Re: Namespaces
          Level 7
          I'm no expert but - Using namespaces is just a simple way to remove
          ambiguity from using like named classes or functions. If you're the only
          developer ever working on your project it may not matter much. But if you
          start using other peoples classes it probably will matter. For example you
          might make a class named Display - and so might some other developer. By
          using a namespace - like your domain name - you can use two same named
          classes in your project: com.domain1.Display, and com.domain2.Display...
          without the namespace you'd have no way to differentiate between the two
          Display classes and would have to rename one - and possibly its methods.
          Many tween classes have a stop() method - Flash has a stop() method -
          namespaces allow Flash to know which stop() method you want to call...

          HTH

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Namespaces
            hciguy Level 1
            Oh okay that makes sense and I can see that but that seems to have to do with just defining a generic namespace. Can't you also sort of attach functions to a namespace? What is the goal there?

            Thanks.
            • 3. Re: Namespaces
              kglad Adobe Community Professional & MVP
              the goal is to prevent name conflicts. so, if have two functions with the same name (like f) in two different namespaces (like ns1 and ns2), they can be referenced by

              ns1::f // and

              ns2::f