Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-31-2008, 03:50 PM   #1
Groady
Senior Member
 
Join Date: May 2006
Posts: 139
Default Where do YOU put your classes?

I've been trying to tidy up some of my own custom classes lately and am trying to decide on the best way to structure my classes.

I'm wondering how YOU structure your packages when working on a project. I find there are certain classes I use regularly (like a custom Math class) and others which are created specifically for the current project (like custom DisplayObject's etc).

I'm trying to figure out if it's best to keep all classes within a master root package OR is it better to separate re-useable classes from project specific classes? I can see a benefit of manually copying classes to a local project structure for backup purposes. Having a global library could cause problems if a method gets renamed and a old project needs re-compiling.

What do you think?
Groady is offline   Reply With Quote
Old 12-31-2008, 04:04 PM   #2
yell0wdart
jordanrift.com
 
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 297
Default

I generally create packages for specific things. I've got a set of utility classes that I reuse across several projects that I keep in a separate package/assembly. With project specific stuff, it's important to create a folder structure that reflects the programmatic structure of your packages, rather than dumping everything into some nebulous "global" namespace.
__________________

bad developer

Jordan Rift
yell0wdart is offline   Reply With Quote
Old 02-07-2009, 03:51 PM   #3
kkbbcute
Guest
 
Posts: n/a
Default

Hows this, I don't even use classes. Never liked it. I'd rather have a 500 line long onEnterFrame function than a class as I like having all the code I'm supposed to be working with all in front of me at the same time so that I can debug more easily if the need arises, as all of my code are in one place. I just use 'for' loops to place any code I need on individual MCs which are named like mc1, mc2, mc3.

It's just me though, wonder if anyone else finds classes weird.
(Not saying that classes suck or anything, just saying that Ifind that I can do without them)
  Reply With Quote
Old 02-07-2009, 11:31 PM   #4
maskedMan
Obfuscated Coder
 
maskedMan's Avatar
 
Join Date: Apr 2008
Posts: 681
Default

I understand where you're coming from kkbbcute, as I once felt the same way. I think it depends really on how you structure your classes whether it's going to be easier to debug a 500 (or is it 5000) line onEnterFrame event than your class library.

For my money, it's much easier to debug classes than a giant procedural program. When objects are well-encapsulated and decoupled you remove needless dependencies, thus making a change in one place runs very little risk of causing unintended screwups elsewhere. Programming abstractly can allow you to swap class objects seamlessly either at compile time or at run time. While there was a time that I liked to be able to "see it all in one place", I've come to prefer only seeing what I need to see at any one time, and a good class structure lets you do just that.

Also, I suppose if you use the IDE exclusively to write your code and don't have a proper developer's tool like FlashDevelop (free) or FlexBuilder (not free) then managing a class library can be painful and require a lot of mental overhead that would be better spent on writing the code. The Flash IDE, since it doesn't recognize your custom classes in its auto complete and doesn't have a fully featured project panel, just makes writing a class-architecture harder than it needs to be.
__________________
man.mask = mask_mc;

Sigh. The AS3 version just doesn't look at nice as
'man.setMask(mask_mc);'
maskedMan is offline   Reply With Quote
Old 02-08-2009, 12:07 AM   #5
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

For general, everyday, reusable classes, I put them in the standard, reverse-domain package structure starting with com.senocular followed by, if possible, the directory name that mirrors what its location would be if it was a native class in the player in the flash.* package. For example, my VirtualMouse class is located in package com.senocular.ui since in flash, most mouse-releated classes are located in flash.ui.

When working with project-specific classes, the same convention is used if the project has its own domain. For example I have a little Flash app with its own domain and its classes are all stored in com.myavatareditor.* because that's where it lives.

If a project does not have its own domain, it usually just gets a single top-level package directory named after the project itself. An example would be something like (now looking at one of my smaller projects) creatures.*.

If any project is to use classes from another source, such as the creatures app needing to use something from com.senocular.*, I would physically copy those com.senocular.* classes over to my creatures project directory. This does a couple things. This gives me access to all required classes in one, easy to find location, makes it easier to package up all source code with its dependencies if needing to give it to someone else or post somewhere publically, and keeps changes from that original code affecting the project since it has a copy of that code in a state where it is known to work for that project.

So... all my general-purpose classes I have somewhere on a common place on my hard drive, but no project actually uses them from that location. Instead they have copies of those classes in their respective project directories with other com.* classes or their own projectname.* classes.

That actually reminds me. In cases where I have projects with classes I think would be reusable or useful in other places, I'll usually throw them into com.senocular.* which I've wanted to do with some of the creatures classes for a while but never have.
__________________
(6)

Last edited by senocular; 02-08-2009 at 12:09 AM..
senocular is offline   Reply With Quote
Old 03-10-2009, 05:03 AM   #6
-Ev-
Senior Member
 
Join Date: Aug 2008
Location: Boston, MA
Posts: 225
Default

I've got a very similar approach to senocular. All my personal reusable classes live in a Code folder on my hard drive that is simply a library of all classes I've written and felt were worthy of reuse. Root directory is com.evanwarner, and past that they are organized by category; data, layout, math, motion...whatever. Any time I want to use one of them, I copy it to my project's development folder.

My core belief is that any classes that collaboratively perform a job should be isolated in a package together. Methods and variables defined as internal should only be accessible to classes that will use them. Any standalone class that performs a job by itself can sit in the same package as other standalone classes, since all access is either public, protected or private.

A project's package organization is the same as my library...com.evanwarner followed by packages according to function of the classes.
-Ev- is offline   Reply With Quote
Old 03-10-2009, 09:32 AM   #7
dimpiax
Member
 
dimpiax's Avatar
 
Join Date: Mar 2008
Location: Ukraine, Kiev
Posts: 85
Send a message via ICQ to dimpiax
Default

I have such structure of my projects:


Project:
+ classes
+ ...
+ com.project.view
+ ...
+ deploy
+ data
+ assets
main.swf


It's very useful
dimpiax is offline   Reply With Quote
Old 03-10-2009, 10:05 AM   #8
Robbus
Member
 
Join Date: Oct 2008
Location: UK
Posts: 32
Default

Out of interest where/when/why did 'com' become the generally accepted default name for the top level classes directory, why not 'classes' for example, or even just 'c'?

Cheers,
Rob
Robbus is offline   Reply With Quote
Old 03-10-2009, 02:39 PM   #9
-Ev-
Senior Member
 
Join Date: Aug 2008
Location: Boston, MA
Posts: 225
Default

It was in effort to make package names unique and create a standard naming convention. Your website URL is unique, so it was a good candidate to use for package naming. It also sort of provides a way to find the author. It was reversed to com.* for two reasons:
1. To provide a more common root folder for packages instead of having all these unique names.
2. To prevent the possible confusion of seeing myurl.com. We automatically see that as a web address, but com.myurl is obviously not a web address.

I'm actually not sure if AS package naming was the first instance of this convention. I've seen it used other places. If you're on a Mac, go into your preferences folder, you'll see that a majority of the preference files are named com.apple.*.plist, com.adobe.*.plist, etc.
-Ev- is offline   Reply With Quote
Old 03-10-2009, 03:04 PM   #10
Robbus
Member
 
Join Date: Oct 2008
Location: UK
Posts: 32
Default

Thanks Ev, I should've said mine was a more generalised question. So what did developers use before the whole internet thing as obviously there wouldn't have been .coms for us all to get excited about?!

Cheers,
Rob
Robbus is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where are the classes? arkum ActionScript 3.0 1 07-31-2007 11:53 AM
Abstract Classes and Interfaces jfred1979 ActionScript 2.0 1 06-21-2007 03:17 AM
Re-use classes across different SWFs FarFeTTu ActionScript 2.0 9 03-27-2007 03:57 PM
Fitting a quiz program into AS2 classes puddle ActionScript 2.0 0 08-28-2005 05:40 PM
as2 classes don't load.. XTC ActionScript 2.0 1 12-10-2004 03:48 AM


All times are GMT. The time now is 12:31 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.