| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Flash Sucks
|
Three good class traits
Note that in the following I'm saying class (to emphasize that this is about class design), but I'm really referring to an instance of that class (or an object). anyway ... - all of the variables in a class are useful for as long as the class lives - all of the methods in a class can be called independently of one another and in any order - only the following methods are called: -- methods that belong to the class -- methods that belong to objects created within the method -- methods that belong to objects which are arguments to the method -- methods that belong to objects stored in the classes variables Thoughts or opinions? None of these things are my creation, but I find them incredibly helpful (in practice) for quickly identifying weak points in my class (besides the usual stuff ... no duplication, complexity, etc.). Try applying these three things to the code you are working with now. Chances are if one of them is being violated it should be moved to a new class (either one that exists or a new one altogether). Of course there are quite a few other things that can be talked about, but these three things are easy to identify and tend to naturally lead me in the direction of a good design. - M |
|
|
|
|
|
#2 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
so how do these apply to build airplanes??
(sorry had to ask bro)
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
|
|
|
#3 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
could you give a bad example and good example of each point. I think that might help me a little.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
#4 | ||
|
Flash Sucks
|
Quote:
Quote:
I hope things are well mang. |
||
|
|
|
|
|
#5 |
|
jordanrift.com
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 297
|
Sounds about right. I've always looked at class design with one thing in mind:
You should be able to describe what your class does in one short sentence. |
|
|
|
|
|
#6 | |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
Quote:
So the first to need is what's the problem: I'm trying to simplify the process of collecting data from a form and sending it server side. I need for the validation and object types to be encapsulated so that it may be changed out. Here's what I got: ![]() IFormCollection.as ActionScript Code:
TextFieldCollection.as ActionScript Code:
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman Last edited by Flash Gordon; 06-11-2008 at 03:23 AM.. |
|
|
|
|
|
|
#7 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
continued.......
FormHandler.as ActionScript Code:
Ok so there are many many problems with this. The first of which I've addressed above. The way it currently validates the input make it very difficult to extend it. Maybe the class is trying to do too much and the client should be more responsible for handling errors in the validation. What you think Michael? How's that mess for a start?
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
#8 |
|
Flash Sucks
|
I need for the validation and object types to be encapsulated so that it may be changed out.
- I know what you mean by validation, but what do you mean by "object types"? |
|
|
|
|
|
#9 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
TextField, comboBox, radioButton, TextInput, etc.....
I was trying to treat the all the same: as a type of IFormCollection.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
#10 |
|
Flash Sucks
|
What about ...
A Form which contains a collection of FormElements. A FormElement has a validate method which accepts a Validator object. A Validator object also has a validate method that returns a boolean. A FormElement can be something like a CheckBox, TextField, InputText, etc. A Validator can be something like ... ZipCodeValidator, CreditCardValidator, etc. You can handle multiple validations by making a CompositeValidator. This is different from what I am going on about in this thread since I'm introducing a new design, but ... I don't know ... these are my initial thoughts. Feedback. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to do a CSS Class that contain an instruction for bolding stuff ? | Bracer | HTML and JavaScript | 1 | 02-20-2008 06:41 PM |
| Can I target a _root variable from another class? | Munkey | ActionScript 2.0 | 6 | 07-06-2007 04:14 PM |
| ColorTransform within custom class | wmbenedetto | ActionScript 2.0 | 2 | 05-12-2006 08:59 AM |
| Database simulated with arrays on a cd-rom | lecasn5 | Components | 61 | 09-07-2004 12:40 PM |
| Is it mandatory to know OOP and class stuff to create a component??? | CyanBlue | Components | 23 | 06-07-2003 02:06 PM |