I.T. Discussion Community!
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphi Prism  Print This     

Class..Object

Languages Focus

In short, a class is a data type, and an object is an instance of a class type. A class has methods (routines), properties (member variables), and a constructor. The current values of the properties is the current state of the object. The UML is one of the diagraming disciplines that allows you to document the various changing states of a series of objects.

Delphi Prism:   class..end..new

Declare your class in the Interface section. Then implement the class in the Implementation section. To create an object instance, use the New keyword. Optionally, you can use Create for backword compatibility with Delphi if you turn it on in the compatibility options. Since Prism does have a garbage collector, you do not have to free the object. If you need to free either unmanaged resources or resources where "timing" is important, implement IDisposable and take control of freeing the object yourself using Dispose.

Syntax Example:

In the interface section:

Cyborg = class(System.Object)
public method IntroduceYourself();
end;

In the Implementation section:

method Cyborg.IntroduceYourself();
begin
MessageBox.Show("Hi, I do not have a name yet.");
end;

On some event like a button click:

var T1: Cyborg;
begin
T1 := New Cyborg;
T1.IntroduceYourself;
  //No need to clean up with managed classes.
  //The garbage collector will take care of it.
end;




Cross Reference Examples:

ASP Classic:   Class..Set..New

Ultra-primitive (no inheritance) but useful and encourages you to think and design using objects. Unlike VB, you can have more than one class per file.

Classes in ASP do support member fields, properties, and methods.

Syntax Example:
'Declare class.
Class Cyborg
  Public Function IntroduceYourself() 
    Response.Write("Hi, I do not have a name yet.") 
  End Function 
End Class
 
'Create object from class.
Set T1 = new Cyborg
T1.IntroduceYourself() 
Set T1 = Nothing      'Be sure to clean up!
C#:   class...new

In C#, you use the class keyword to specify a class and you signify its parent with a colon and the name of the parent class. When you instantiate an object from a class, you use the new keyword.

Syntax Example:

Define class:

public class Cyborg : System.Object
{
public virtual void IntroduceYourself()
{
MessageBox.Show("Hi, I do not have a name yet.");
}
}

Create object from class:

Cyborg T1 = new Cyborg();
T1.IntroduceYourself();
//No need to clean up with managed classes.
//The garbage collector will take care of it.
C++:   Yes More Info / Comment
Corel Paradox:   Not Supported
Delphi:   class..end..Create

Declare your class in the Interface section. Then implement the class in the Implementation section. To create an object instance, call the class constructor (usually named Create). Since Delphi does not have a garbage collector, you have to also free the object usually with either Free or FreeAndNil.

Syntax Example:
//Interface section:
TCyborg = class(TObject)
public
procedure IntroduceYourself;
end;
 
//Implementation section;
procedure TCyborg.IntroduceYourself;
begin
ShowMessage('Hi, I do not have a name yet.');
end;
 
//Some event like a button click:
var
T1: TCyborg;
begin
T1 := T1.Create;
T1.IntroduceYourself;
  FreeAndNil(T1);      //Be sure to clean up!
end;
Java:   class..new

Unlike languages such as C++ and Object Pascal, every line of code written in Java must occur within a class.

Syntax Example:
//Declare class.
public class Cyborg {
  //Fields.
  private String cyborgName;
  private int age;
 
  //Constructor.
  public Person() {
  cyborgName = "unknown";
  age = 0;
  }
}
//Create object from class.
Cyborg p = new Cyborg();
p.getClass(); //From the Object base class.
JavaScript:   Limited, class..new

Creating classes in JavaScript is not really OOP, but rather a super type. That is, a type that has some class-like features but is missing the necessary OOP requirements.

There is nothing in Javascript to stop you from accessing the functions within your class outside of the class so this is not fully OOP but is usable.

Syntax Example:
//Class definition.
function Person() {
this.name = 'unknown';
this.age = 0;
}
 
//Use object created from class.
var Lisa = new Person();
Lisa.name='Lisa';
Lisa.age=28;
VB Classic:   Yes

One class per file. File must use a .cls extension (instead of .bas). You can include your classes in your project (a traditional OOP approach) or compile them to a DLL or ActiveX EXE, register them, and use them that way (a uniquely VB approach).

More Info / Comment
VB.Net:   Class..End Class..New

Declare and implement VB.Net classes after the form class or in their own .vb files. Unlike VB Classic, you can have more than one class in a .vb class file (VB classic uses .cls files for each class).

Syntax Example:

Class definition:

Public Class Cyborg
  Inherits Object
 
  Public Sub IntroduceYourself()
  MessageBox.Show("Hi, I do not have a name yet.")
 End Sub
End Class

Some event like a button click:

Dim T1 As New Cyborg
T1.IntroduceYourself()
//No need to clean up with managed classes.
//The garbage collector will take care of it.




-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,128 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech