|
Prev: Deriving - .NET example
Next: Polymorphism Downsides (was: what's the future of Object Oriented Programming)
From: Oliver Wong on 8 Sep 2006 17:13 "Phlip" <phlipcpp(a)yahoo.com> wrote in message news:5mjMg.2431$MF1.1992(a)newssvr25.news.prodigy.net... > VV wrote: > >> How much of OO is really needed in todays web based technology >> environment. > > All of it. You need OO each time you see code that use 'if' or 'switch' > flagged by some value that is a type, not a scalar. > > Common example: Your users come in two types, Guest and Premium. So you > store the boolean isPremium in the database, and then all over your > project, from the data layer to the JavaScript, you write "if (isPremium) > (whatever} else {whateverElse}" everywhere. > > You need polymorphic types there. You should instead have a user type with > two sub-classes. User.whatever() will call one behavior for the Guests, > and another for the Premiums. Usually the PHP code is like: Include.php: function checkPremiumFlag() { if (isPremium) { return. } else { display offer to upgrade account. stop further processing. } } checkPremiumFlag() PageA.php: include('Include.PHP'); Display Page A contents. PageB.php: include('Include.PHP'); Display Page B contents. Are you're proposing something like: Guest.php: class Guest { displayPageAContents() { display offer to upgrade account. } displayPageBContents() { display offer to upgrade account. } } Premium.php: class PremiumUser { displayPageAContents() { Display Page A contents. } displayPageBContents() { Display Page B contents. } } PageA.php: user.displayPageAContents() PageB.php: user.displayPageBContents() ? - Oliver
From: Phlip on 8 Sep 2006 17:57 Oliver Wong wrote: > Are you're proposing something like: > > Guest.php: > class Guest { > displayPageAContents() { > display offer to upgrade account. > } > > displayPageBContents() { > display offer to upgrade account. > } > } > > Premium.php: > class PremiumUser { > displayPageAContents() { > Display Page A contents. > } > > displayPageBContents() { > Display Page B contents. > } > } > > PageA.php: > user.displayPageAContents() > > PageB.php: > user.displayPageBContents() > > ? What's the narrowest thing, if any, that differs over the two pages? Put everything else into the calling routine. (Abstract Template Pattern.) Your system duplicates a lot of stuff. We can see that duplication easily, without even inspecting the source of displayPageAContents(), if we follow a careful naming convention. Many elements of the names of displayPageAContents() and displayPageBContents() duplicate! To remove duplication without adding complexity, one often must use OO techniques. So OO is relevant to all programming. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
From: frebe73 on 9 Sep 2006 04:57 > I recently launched a business written completely with free tools like > php and AJAX. I worked hard to give everything a structure like we OO > programmers are so particular about but honestly there was minimal > dependence on OO. > > The extend of my reusability might have been include pages, constants > etc. > > Are many of you finding widespread use of OO in the web world? First, what is your definition of OO? As you see people claim that HTML and web browsers are OO. So what is not OO? For some OO is everything, and everything is OO. For the rest of us, the main thing with OO is that it can handle polymorphism in an improved way. The benefits of OO is only obvious if your problem space contains a lot of polymorphic types. For average web business/enterprise application, this is simply not the case. And it is also very easy to overuse polymorphism. Types like customers and employess is normally not polymorphic. In many cases, OO programming languages (like Java) has a big disadvantage because they force you to use objects for everything, even in situations when you only need functions (the main method for example). OO is a useful technology that you may benefit from in some situations. But it should only be used as a complement to other technologies. This is exactly the path the web languages like PHP, Python and Ruby is walking. Fredrik Bertilsson http://frebe.php0h.com
From: frebe73 on 9 Sep 2006 05:00 > Re-use is a happy side-effect of good designs. The primary goal is managing > dependencies between modules, by making them more pluggable. Your web page > can work in any browser, so the HTTP and HTML are like adapter layers. The > actual browser gives alternate behaviors to the common inputs. > > For example, AJAX is a data stream to an Object - any web browser. The data > stream is a Message, where the JavaScript in the web page in the browser is > the Method that responds to that Message. Pure OO. Maybe COBOL is OO too? Or even SQL? Fredrik Bertilsson http://frebe.php0h.com
From: frebe73 on 9 Sep 2006 05:08
> I personally found that the web based stateless environment is not that > conducive to taking advantage of OO. We ended up borrowing a lot of > benefits exposed by procedural languages but minimal from OO. This is the same for all distributed applications, not only web applications. You have the data in one tier, functionallity in another tier. How can encapsulation be achieved under these circumstances? A stateless application server publish a number of functions. Objects can only be used within single server calls. > I am wondering if others have a similar experience? You are not alone. > If so, where does OO fit in with high level applications (not system based) on the > web. OO fit when you have polymorphic types. Fredrik Bertilsson http://frebe.php0h.com |