OOP vs Procedural

Okay, I suppose that certain especially simple tasks should be done the old fashioned way. Banners come to mind, using a complex OOP approach on something like that could be kinda dumb.

Donā€™t shatter my illusion Senocular, I like to think Iā€™m a real programmer! :lol:

Could you elaborate please sen?

Creatify kindly converted a function of mine (motion graphics) into classes, and he did a perfect job, itā€™s exactly the same, but it uses 10% more CPU power.

Okay, maybe we could discuss an example. Letā€™s say I was going to build a portfolio site. Iā€™ve got three basic sections: about, contact, and of course, portfolio.

The only semi-complex part of this site is the portfolio section. The portfolio is broken up into five subcategories. And each category has an average of seven or so projects. All the information about each project is, of course, stored in a database. That data is retrieved with a server-side script that formats it into XML. We, of course, pull it into flash and sort through it with the XML object.

Would it be a pain to give me a summary of how you might achieve this with OOP?

[QUOTE=rumblesushi;2340242]Could you elaborate please sen?

Creatify kindly converted a function of mine (motion graphics) into classes, and he did a perfect job, itā€™s exactly the same, but it uses 10% more CPU power.[/QUOTE]

Basically its the extra overhead resulting from the creation of objects and method calls needed to facilitate communication between those objects. Obviously as you start reducing that overhead and take a more direct, procedural approach, youā€™ll gain some performance benefits. But usability, extensibility, and maintainability (+ ility of your choice) start to waver.

You might do it something like this:


--DocumentClass 
------SiteDataClass
             ----LoadXML() method
             ----get XML method
------SiteInterfaceClass
             ----DrawPortfolio() method
             ----DrawAbout() method
             ----DrawContact method

Obviously thatā€™s really loose, but it might give you a brief idea of how you could do it.

[quote=Anogar;2340292]You might do it something like this:


--DocumentClass 
------SiteDataClass
             ----LoadXML() method
             ----get XML method
------SiteInterfaceClass
             ----DrawPortfolio() method
             ----DrawAbout() method
             ----DrawContact method

Obviously thatā€™s really loose, but it might give you a brief idea of how you could do it.[/quote]

Thatā€™s a good diagram. What happens if you have tons of complex animation in your portfolio movie. I know I could have a movieclip in my library with a class name of ā€œportfolio.ā€ And I could put it on the stage from the document class by referencing its class name. What would be the real difference if that movieclip sits on say frame 15 of the main timeline?

It would be silly to write >2000 lines of custom actionscript on the timeline.
Use classes to break down large complex scripts into more manageable sections.
50 lines of basic website navigation code is easier to manage on the timeline IMO.

BTW, Lee Brimelow recently released the ā€œ[COLOR=ā€œBlueā€][U]snippet panel[/U][/COLOR]ā€ for Flash.
Itā€™s a nifty place to store frequently used blocks of code, and makes scripting on the timeline a snap.
For example, I have all of the code required to set up a complete website stored in the snippets panel.
Takes about 30 seconds to set up the basic code for the entire site, and it works correctly the first time, every time.:slight_smile:

You might want to consider interestingness when deciding which programming style you want to use. Personally, my projects seem to turn out better when I am able to find an amusing way to solve some given problem.

Well you should always be using the Document Class so you would always be working with classes and at least one object. And you are always using other object oriented classes because your going to extend a DisplayObject, so technically you canā€™t program procedurally. But Iā€™d say only program procedurally if you donā€™t happen to need any other classes. But that would be a pretty simple program.

[QUOTE=Krilnon;2340379]Personally, my projects seem to turn out better when I am able to find an amusing way to solve some given problem.[/QUOTE]

Youā€™re totally right :slight_smile:

If you donā€™t mind, can you give me an example? :slight_smile:

^ Check your PMs.

[QUOTE=Krilnon;2340473]^ Check your PMs.[/QUOTE]

Yeah PMS is a *****.

har har har :expressionless:

[quote=TheCanadian;2340504]Yeah PMS is a *****.

har har har :|[/quote]

yuk yuk :hugegrin:

I use like a very basic oop way of handling even the smallest of things, I write out functions to handle alot of stuff, have like a main function. So its like I only use one class, except I donā€™t put it in the document class rather on the frame because I like the way I donā€™t have to type out public or private before my functions and variables.

For a web site project like digitalmatt was talking about, I would use Anogar method, but you can have like animation classes and other things to go along with his method itā€™s just an outline.

[quote=ajcates;2340511]I use like a very basic oop way of handling even the smallest of things, I write out functions to handle alot of stuff, have like a main function. So its like I only use one class, except I donā€™t put it in the document class rather on the frame because I like the way I donā€™t have to type out public or private before my functions and variables.

For a web site project like digitalmatt was talking about, I would use Anogar method, but you can have like animation classes and other things to go along with his method itā€™s just an outline.[/quote]

Thatā€™s sort of the way I program. For a task I know Iā€™ll repeat over and over, I write flexible functions I can easily call and maybe pass some arguments to ā€“ though thatā€™s probably considered programming 101.

To me, though code can be more manageable written in custom classes, it seems like thereā€™s a time and place for it. But, since Iā€™ve been practicing with AS3ā€™s document class, it makes so much more sense to write custom classes. At the same time, however, I feel Iā€™m writing a whole lot more code to simple things that can be achieved with basic functions sitting in a frame on the main timeline.

Am I making sense?

There are some very real reasons to do object oriented programming the way itā€™s intended, in class files. Things like public and private have very real meanings, and when used properly they make your life a whole lot easier - especially when working with multiple developers or sharing classes between multiple projects.

Itā€™s hard to understand the power of OOP until youā€™ve spent some good time using it, and seeing how much time it saves you over the course of a few projects.

[quote=Anogar;2340517]There are some very real reasons to do object oriented programming the way itā€™s intended, in class files. Things like public and private have very real meanings, and when used properly they make your life a whole lot easier - especially when working with multiple developers or sharing classes between multiple projects.

Itā€™s hard to understand the power of OOP until youā€™ve spent some good time using it, and seeing how much time it saves you over the course of a few projects.[/quote]

Yeah, thatā€™s another thing that the Java developers I work with tell meā€¦OOP makes working on large team projects immensely easier. Especially if all the developers are working on different, but related chunks of code.

Itā€™s also very helpful when you want to reuse a class between projects. The whole thing is really more about ways to make your projects easier over the long run.

I do every Flash project solely with AS3 (I donā€™t even own CS3, wtf right) so without OOP it would be freaking redic. One of the cool things about AS3 is helper classes. It allows you to fully utilize OOP but without having to create a billion different classes which youā€™ll never ever use again in a million years.

Take this for example:

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import jm.geom.Point3D;
	public class ShiftingNodeNetwork extends Sprite {
		private var nodes:Array = new Array();
		private var maxDistance:Number;
		public var axisRotations:Object = new Object();
		public function ShiftingNodeNetwork(width:Number, height:Number, depth:Number, distance:Number, ease:Number, numNodes:Number) {}
		public function start():void {}
		public function stop():void {}		
		private function connect(evt:Event):void {}
	}
}

import flash.display.Shape;
import flash.events.Event;
import jm.geom.Point3D;
import jm.math.Random;
class RandomNode extends Shape {
	private var coord:Point3D;
	private var targCoord:Point3D;
	private var ease:Number;
	private var wc:Number;
	private var hc:Number;
	private var dc:Number;
	public function RandomNode(w:Number, h:Number, d:Number, e:Number) {}
	private function move(evt:Event):void {}
	public function get location():Point3D {}
	public function start(evt:NodeEvent):void {}
	public function stop(evt:NodeEvent):void {}
}

Thatā€™s just a snippet from one of my experiments with mose of the code removed for clarity. I used the RandomNode as a helper because when would I ever need that class again? Now the classes in there that I do use between multiple projects (like NodeEvent, Point3D) have there own class file so I can import them for another project.

After a while you can start making your own library, organized into packages, that you can access from any file. Saves you from having to search through multiple timelines of code to find what youā€™re looking for.