views:

306

answers:

2

When I create a new class file in Flex 3 it warns me that I should not use the default package.

I personally never used packages before, but think that packages won't make things any more easier since I just want to be able to use all my classes everywhere without importing all kinds of packages which I would have to remember the names and their purposes of.

My question is if my behaviour will result in problems in the future. And if so, why? Or am I not alone here?

+1  A: 

If you dislike creating too many packages, create just one and put into it everything you have now in the default package.

Why may you need packages? It is:

  • A way to avoid problems with duplicate filenames when you share you code
  • A way to organize your code

Like if you have your classes "in a wild" when they are outside the packages and then "domesticate" them and they can't do anybody any harm. If you don't wish to share your code, there's still a reason for using packages, because in time your code gets more complex and you want to have some means to organize it into some logical structure.

Malcolm
So what's the advantage of doing that?
Tom
See my edit, I have added information to the answer.
Malcolm
Thank you very much.
Tom
+1  A: 

I think the best reason to use packages is that you can use the best name for your class for the intended purpose without fear of naming conflicts. Say you have a need for a class that contains information on events. Flash already has an Event class defined, but because it is defined in a package, you can reuse the name (preferably in your own package) without a conflict. Without packages you'd be forced to name your class something else (MyEvent) that is less than ideal for the purpose. This extends to the classes that you create. By putting them in packages, you also don't need to worry about naming conflicts in your own library of classes when creating classes with the same names, but different functions.

tvanfosson
I'll start using packages. :)
Tom