Re: Classes functions....help!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kevin Spencer (kspencer_at_takempis.com)
Date: 09/17/04


Date: Fri, 17 Sep 2004 16:44:34 -0400

Hi Simon,

You need to study up on object-oriented programming, because .Net is fully
object-oriented. If you don't understand OOP, you're lost. I can give you a
brief here, but you really need to study up on your own until you "get it."

The first thing you need to understand is the difference between procedural
and object-oriented programming. The difference is that in procedural
programming, the instructions are executed in a specific order, with a
number of side trips to execute functions. In object-oriented programming,
there are logical groupings of functionality and data that are called
classes. A class is simply a container for functionality and data. There is,
of course, a procedural aspect to OOP, but rather than moving in an orderly
fashion through a procedural path, execution jumps around from one object to
another. OOP also includes events. An event is when a piece of code informs
the Operating System that something significant has happened, and the OS
broadcasts that news to any class listening for it (via an event handler).
The event handler then independently executes the code that handles the
event.

The chief components of OOP are:

Encapsulation - Classes have the ability to hide or reveal data and
functionality contained within them. By the use of Private, Public, and
other class scopes, you can hide anything in a class that you don't want
accessed from outside the class (a bit oversimplified, but hopefully you get
the idea). It's all a matter of scope.

Inheritance - Classes can "inherit" from other classes. If a class inherits
another class, it has (a bit oversimplified again) all of the data and
functionality of the class which it inherits. This is particularly useful
for writing reusable and compact code. For example, if you want a text box
to do everything that a TextBox class does, but add some functionality to it
as well, you can simply declare a class that inherits TextBox, and add the
funtionality to it.

Polymorphism - Classes can have the same programming interface, but behave
in different ways. This is done by inheriting other classes and overriding
certain methods and properties. It can also be done by the use of
Interfaces. An Interface is like a contract that says "if you use me, you
must include such and such a method or property, but it can operate any way
you want it to." For example, both trucks and cars are of the same type
(vehicle). However, the implementation of vehicle will be different in a
truck than in a car.

Functions in procedural and OOP work basically the same. The chief
difference is that functions are encapsulated in classes with OOP.

Google Object -Oriented Programming to get a better picture. This is less
than a thumbnail. I would not recommend trying to write a single line of
code without understanding the basics of OOP.

Also, you may want to download the FREE Microsoft .Net SDK:

http://www.microsoft.com/downloads/details.aspx?FamilyId=9B3A2CA6-3647-4070-9F41-A333C6B9181D&displaylang=en

-- 
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Simon Harris" <too-much-spam@makes-you-fat.com> wrote in message
news:OscOhGPnEHA.2612@TK2MSFTNGP15.phx.gbl...
> Hi All,
>
> I'm new to asp.net (Migrating from 'Classic' ASP)
>
> I'm having troubles working out classes, functions etc...
>
> Current situation is this:
>
> index.aspx displays datalist with links to sites - If no link found in DB,
I
> want to display a message instead. I worked out I need a function to do
this
> (No if statements based around DB values allowed in datalist)
>
> Questions are:
> - Where do i build the function? In a seperate class file? In the code
> behind for index.aspx?
>
> - How do I then call this function/class? I understand the syntax of
> actually calling the function, its more a case of how do I make the
> function/class available to index.aspx?
>
> - How do I return a value from the function/class? I want to input 2
> values - ID and Domain, if domain is empty, I want to return 'No Site
> Listed' if not, I want to return the domain.
>
>
> Sorry if this is all a bit vague - I may well be asking the wrong
> questions???!
>
> Thanks,
> Simon.
>
>


Relevant Pages

  • Re: an old geezer running visual studio for the first time
    ... Maybe your idea of OOP is not as complete as it can be. ... sounds more like componentization than OOP in general. ... functionality is in a common base class. ... > closing rapidly the connetion again) and only change data by way of SQL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Object/Relational Mapping is the Vietnam of Computer Science
    ... procedural programming is sometimes the way to go. ... even OOP is really procedural stuff that is just highly organized. ... It's an approach I used a couple years back when writing an Apple ... expose the full range of AE functionality and created fewer hidden ...
    (comp.lang.ruby)
  • Re: [PHP] Creating new site
    ... Someone mentioned CakePHP which utilizes MVC. ... porting my stuff to the Zend Framework which makes MVC optional, ... I have coded in PHP for quite a while and understand OOP and OOP in PHP, however I don't really have any experience building sites or apps from scratch using OOP/MVC. ... For those that need total freedom to do things the way they want but need some pre-built functionality to make it quicker, Zend seems to be the choice. ...
    (php.general)
  • Re: an old geezer running visual studio for the first time
    ... > Maybe your idea of OOP is not as complete as it can be. ... so instead of placing common functionality in utility ... > functionality is in a common base class. ... >> closing rapidly the connetion again) and only change data by way of SQL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Does anyone in Delphi land NOT use OOP
    ... Of course, if you passed a child "object" directly to a parent function, the parent function would not know to call the child function. ... But you can make that same mistake in most OOP languages by poorly designing your classes. ... There is no requirement that object-oriented programming requires an object-oriented language. ...
    (borland.public.delphi.non-technical)