views:

239

answers:

2

It seems that while I strive to maintain OO principles, it all seems so contrived or unnatural.

+5  A: 

My advice is to not get too dogmatic about OO principles. They work well, but sometimes when people say they're striving to maintain OO principles it can mean that they're creating a class for everything, even when it's not really appropriate. Things also get less unnatural as you get used to them, such as "x = 3" is natural for an assignment, even though someone with a math background would think it's unnatural.

You could also try taking a look at existing OO web apps and design patterns. A common OO design pattern is the MVC pattern, which is supported (almost enforced) by Ruby on Rails and Django. Do a search for MVC.

Dietrich Epp
the original OO-MVC makes sense only for GUIs, the more common web-MVC is more layered than OO.
Javier
Javier, can you elaborate on this point with regard to the layering?
zsharp
the GUI-MVC (made popular on SmallTalk) was modular and OOP; each module had three objects more or less tightly coupled, forming a single module instantiated when needed. web-MVC, OTOH, is three layers, not objects, each one abstracting some aspect to give a higher-level access to some part (storage, presentation and control flow). they're not composed in a bigger subsystem, and they don't represent a visual element, together they manage a whole app (or subapp). totally different things, maybe related only at a philosophical level, not at a design level.
Javier
+4  A: 

If you think of objects as constructs for holding state information, the definition of "object oriented" becomes strained by the stateless nature of web requests. However, stateless objects are still objects and web applications can follow OO design principles within that context.

Jekke
yes, this is what i meant.
zsharp