views:

126

answers:

4

I am building a web application and have been told that using object oriented programming paradigms affects the performance of the application.

I am looking for input and recommendations about design choices that come from moving from One Giant Function to a Object-Oriented Programming Interface.

In order to be more specific: If a Web Application used OOP and created objects that live for a very short time period. Would the performance hit of creating objects on the server justify using a more functional ( I am thinking static functions here ) design.

+1  A: 

Wow, big question, but in short (and comment if you want more info) OOP code/practises (ideally well written at that) will give you far more maintainability, testability and joy to code in that OGF coding.

As for the speed arguement, that really is only an issue if you are really trying to squeeze every possible last ounce of CPU out of a server thats going to get hammered. In which case you are problably doing something wrong and need to think about better/more servers or you work for NASA or are doing it for a dare.

Pete Duncanson
+1  A: 

I dont know about performance but it definitely makes it easier to maintain.

I am looking for input and recommendations about design choices that come from moving from One Giant Function to a Object-Oriented Programming Interface.

as David suggested, answering the above will require lot of pages.
Perhaps you should be looking at frameworks. They make some design choices for you.

Omnipresent
A: 

The most popular way of designing a web app with OOD/OOP is to use the Model-View-Controller pattern. To summarise the 3 main participants:

Model - I'm the stuff in the problem domain that you're manipulating.

View - I'm responsible for drawing and managing what you see in the browser. In web apps, this often means setting up a html template and pushing name-value pairs out into it.

Controller - I'm responsible for handling requests that come in from the web and working out what to do with them and arranging with the other objects to get that work done.

Start with the controller...

Views and Controllers often come in pairs. The controller accepts the HTTP request, works out what needs doing - and it either does it (if the work is trivial) or delegates the work to another object to do. Typically it find the view that's to be used and gives it to the object that's doing the actual work to write output into.

What I've described here corresponds with what you'd expect to find in something like Ruby on Rails.

Making lots of objects that you use once is certainly a concern - but I wouldn't worry about that aspect of performance up front. Proper virtual machines know how to manage short-lived objects. There's plenty of things you can do to speed up a web app - and I would start by sacrificing the benefit of clear organization for a speed up that might not even be the most important optimization...

MVC isn't the only way to go, there are other patterns like Model-View-Presenter and some really unusual approaches like continuation servers (e.g. Seaside) - which reuse the same objects between HTTP requests...

cartoonfox
A: 

Yes. When doing an OO approach to web app development (using Seaside) I can deliver functionality so much faster that I have sufficient time to think about how to deliver the right amount of performance.

Stephan Eggermont