OOP vs Procedural

I’m sure this has been asked around here before. But now that we have Actionscript 3.0, there is so much temptation for me to attempt to build every project to be object-oriented.

How can we know when to choose OOP over Procedural? What should be considered?

The only thing that I can really think of is that if the project is huge, OOP would be a safer bet. But, then again, that might not necessarily be true.

How do I decide?

Once you get into the habit of programming with an OOP mentality i don’t think i would approach any project, no matter the size, in a non-OOP way. It’s just far more maintainable, tidy, and easier to organise. A project would have to be really really small to justify procedural based programming. But then i know some people think otherwise.

An object oriented approach is pretty much always better. I can’t think of a situation that should be approached with outdated coding practices. :stuck_out_tongue:

[QUOTE=Anogar;2340232]An object oriented approach is pretty much always better. I can’t think of a situation that should be approached with outdated coding practices. :P[/QUOTE]

Performance :wink:

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?