When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Data Warehouse Architect (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Published: Monday, September 18, 2000

Using Object-Orientation in ASP.NET : Encapsulation, Part 2
By Ian Stallings


  • Read Part 1

  • In Part 1 we examined the basics of encapsulation and a simple Foo class. In this page we'll examine how to utlize this class (thereby showing the benefits of encapsulation)! For our example, we'll call this class from our ASP.NET file using the following code:

    - continued -

    <%@ Import Namespace="KungFoo" %>
    <html>
    
    <style>
    
      div 
      { 
        font: 8pt verdana;
        background-color:cccccc;
        border-color:black;
        border-width:1;
        border-style:solid;
        padding:10,10,10,10; 
      }
    
    </style>
    
    <script language="C#" runat="server">
    
      public void Page_Load(Object sender, EventArgs E) {
    
        Foo foo = new Foo();
    
        Message.InnerHtml += foo.getPhoneNumber() + "<p>";
    
        foo.setPhoneNumber("702-555-1212");
    
        Message.InnerHtml += foo.getPhoneNumber() + "<p>";
    
    
      }
    
    </script>
    <body style="font: 10pt verdana">
      <b><h3>Simple Biz Obj</h3></b>
      <br><br>
    	
      Object Output:<br>
      <br>
    	
      <div id="Message" runat="server"/>
    
    </body>
    </html>
    

    This should produce the following output:

    Screen shot of the above example.

    Notice that when we did not alter the state of the object directly. Instead we called a behavior of the object named setPhoneNumber. We aren't worried about how this is accomplished. That's the great part. It hides the implementation details. For all we know there could be a "Hamster in a Wheel" class that makes this happen.

    And that wraps up encapsulation. In our next article we will discuss inheritance and how it can be used to develop ASP.NET to create reusable and extensible code.

    Happy Programming!

  • By Ian Stallings


    Attachments:

  • Download the C# example files in ZIP format
  • Read Using Object-Orientation in ASP.NET : Overview
  • Visit the C# Article Index
  • Visit the ASP.NET Article Index


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article


  • The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers