Presentation is loading. Please wait.

Presentation is loading. Please wait.

OOP and Web Applications Michael Juřek Architect Evangelist Microsoft Corporation.

Similar presentations


Presentation on theme: "OOP and Web Applications Michael Juřek Architect Evangelist Microsoft Corporation."— Presentation transcript:

1 OOP and Web Applications Michael Juřek Architect Evangelist Microsoft Corporation

2 Agenda Web development – overall context Web development – overall context OOP Principles and ASP.NET OOP Principles and ASP.NET ASP.NET object internals ASP.NET object internals  Lifetime issues  Maintaing state  Handling events

3 Desktop Development OOP oriented for years OOP oriented for years Great tools (Visual Basic, Delphi, …) Great tools (Visual Basic, Delphi, …) Visual composition of application UI Visual composition of application UI Developer wires the objects through interaction via events Developer wires the objects through interaction via events Lots of components available: Lots of components available:  Packaged with a tool  For free  For money  Grow your own Only drawback = COST OF DEPLOYMENT Only drawback = COST OF DEPLOYMENT

4 ASP / PHP – fast facts Revolutionary at their time (1996) Revolutionary at their time (1996) Most popular web development environments Most popular web development environments Linear programming model (up-down) Linear programming model (up-down) Hard to maintain code, mixing of logical layers, “spaghetti code” Hard to maintain code, mixing of logical layers, “spaghetti code” Impossible to provide real development environment (-> expensive development) Impossible to provide real development environment (-> expensive development) Other technologies suffer from similar pains (JSP, PHP, Cold Fusion) Other technologies suffer from similar pains (JSP, PHP, Cold Fusion)

5 ASP.NET – goals Be object oriented Be object oriented Mimic desktop paradigm - “Visual Basic for Web” Mimic desktop paradigm - “Visual Basic for Web” Much less lines of code (reduced costs) Much less lines of code (reduced costs) Keep application layers distinct (presentation, logic) Keep application layers distinct (presentation, logic) Native, no scripting (performance !!!) Native, no scripting (performance !!!) „Full“ languages - Visual Basic, C#, JScript ® „Full“ languages - Visual Basic, C#, JScript ® Abitilities: Abitilities:  Reliable, Maintainable, Scalabled, Deployable

6 Power of ASP.NET

7 Agenda Web development – overall context Web development – overall context OOP Principles and ASP.NET OOP Principles and ASP.NET ASP.NET object internals ASP.NET object internals  Lifetime issues  Maintaing state  Handling events

8 ASP.NET pages: Principles Server-side controls Server-side controls  Encapsulate visual elements, interact with user  Generate events (value has changed, button was pressed, mouse click, …) Execution is not linear !!! Execution is not linear !!!  Event fired in every execution phase  Init, Load, Render, Unload, etc. Code hooked on events Code hooked on events  Executed during processing or by user action  May be part of ASP.NET page, in separate file or separate dll library

9 Server-side controls Page class represents web page Page class represents web page  Hierarchy of controls  Page is the root of hierarchical tree  Even static text is LiteralControl object behind the scenes At the end of processing Page.Render() is being called At the end of processing Page.Render() is being called  Propagated down the tree of controls  Each control generates its HTML representation  Multiple client technologies may be supported  DHTML, HTML 3.2, WML, atd. Fully customizable look of control Fully customizable look of control  Total control with the help of Template class

10 OOP: Inheritance All controls inherit from abstract WebControl and Control classes All controls inherit from abstract WebControl and Control classes Page itself inherits from Control, too Page itself inherits from Control, too Inheritance is everywhere, e.g.: Inheritance is everywhere, e.g.:  Control (generic, Children, Parent, …)  WebControl (web style specific, width, …)  ListControl (working with lists, Items, …)  DropDownList  ListBox

11 OOP: Encapsulation Every control is fully responsible for behaving as expected Every control is fully responsible for behaving as expected  E.g. it must render HTML that works in common web browsers How to change control’s behavior? How to change control’s behavior?  By setting properties  By calling methods  By setting external objects (context) – but it’s a control’s sole responsibility how it reflects this information

12 OOP: Polymorphism Control defines basic behavioral characteristics by defining methods as virtual (overridable) Control defines basic behavioral characteristics by defining methods as virtual (overridable) Examples: Examples:  Render()  LoadViewState(), SaveViewState()  CreateChildControls()  OnInit, OnLoad, OnUnload  …

13 ASP.NET Experience

14 Agenda Web development – overall context Web development – overall context OOP Principles and ASP.NET OOP Principles and ASP.NET ASP.NET object internals ASP.NET object internals  Lifetime issues  Maintaing state  Handling events

15 Object lifetime Objects cannot live in client’s browser: Objects cannot live in client’s browser:  No Java Applets  No ActiveX controls  These were unsuccessful technologies Objects live on the server: Objects live on the server:  No persistent connection between client and server (further – think about web farm)  Live only during request processing (~ ms)  Consequences:  You have to keep state somewher  You have to relay events from client to server

16 Maintaining object state Database? Database?  Correct from architectural perspective  Problematic performance, often “overkill” Web server process? Web server process?  Memory consumption, open door for DOS attacks  What about a web farm? Client? Client?  Need of encryption and digital signatures  Increased client/server traffic (delays, money)  Least evil, this is the default  “ViewState” as a hidden HTML form field

17 Web Forms Web page lifecycle Page_Load Page_Render, Unload Textbox1_Changed Button1_Click Events 1. „Change“ events 2. „Action“ events Page created and initialized Page resources released

18 Handling event (PostBack) Server Browser Info processed Event Event handled Event info Updated page Calls event handling routine

19 Summary Object oriented programming makes development much more efficient Object oriented programming makes development much more efficient Web development is no exception Web development is no exception ASP.NET is the only fully OOP- oriented web development technology available today ASP.NET is the only fully OOP- oriented web development technology available today

20 © 2001 Microsoft Corporation. All rights reserved.


Download ppt "OOP and Web Applications Michael Juřek Architect Evangelist Microsoft Corporation."

Similar presentations


Ads by Google