Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphi PrismOOP Details  Print This     

Cross Ref > OOP Details

By Mike Prestwood

Delphi Prism versus ASP Classic: A side by side comparison between Delphi Prism and ASP Classic.

OOP Details

More object oriented (OO) stuff.


[Other Languages] 

General Info: Abstract Class / Abstract Member

An abstract class member is a member that is specified in a class but not implemented. Classes that inherit from the class will have to implement the abstract member. Abstract members are a technique for ensuring a common interface with descendant classes. An abstract class is a class you cannot instantiate. A pure abstract class is a class with only abstract members.

Languages Focus

Abstraction is supported at various levels with each language. A language could enforce abstraction at the class level (either enforcing a no-instantiation rule or a only abstract members rule), and with class members (member methods and/or properties).

Delphi Prism:   abstract, override

Prism supports abstract class members and abstract classes using the abstract keyword.

An abstract class is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties.

An abstract member is either a method (method, procedure, or function), a property, or an event in an abstract class. You can add abstract members ONLY to abstract classes using the abstract keyword.

Alternatively, you can use the empty keyword in place of abstract if you wish to instantiate the abstract class. Then you override it in a descendant class with Override.

Syntax Example:
Cyborg = public abstract class(System.Object)
//You can put "virtual; abstract;"
  //but it's implied with just "abstract;"
  method Speak(pMessage: String); abstract; 
method Walk; virtual; abstract;
Series600 = public class(Cyborg)
procedure Speak(pMessage: String); override;
procedure Walk; override;
ASP Classic:   Not Supported

Class Helper

[Other Languages] 

A. In Dephi, class helpers allow you to extend a class without using inheritance. With a class helper, you do not have to create and use a new class descending from a class but instead you enhance the class directly and continue using it as you always have (even just with the DCU).

B. In general terms, developers sometimes use the term to refer to any class that helps out another class.

Delphi Prism:  "Class Helpers" Not Supported

Although Delphi for .Net did support class helpers starting with Delphi 8, its replacement (Prism) does not, at least not yet.

ASP Classic:  "Class Helpers" Not Supported

Code Contract

[Other Languages] 

A.k.a. Class Contract and Design by Contracts.

A contract with a method that must be true upon calling (pre) or exiting (post). A pre-condition contract must be true when the method is called. A post-condition contract must be true when exiting. If either are not true, an error is raised. For example, you can use code contracts to check for the validity of input parameters, and results

An invariant is also a code contract which validates the state of the object required by the method.

Delphi Prism:  "Class Contracts" require, ensure

Prism supports class contracts with its require and ensure keywords. The require keyword is a pre condition that must be true when the method is called. The ensure keyword is a post condition that must be true when a method exits. With either, if the condition evaluates to false, then an assertion is generated.

The require and ensure keywords will expand the method body to list the preconditions; both sections can contain a list of Boolean statements, separated by semicolons.

Syntax Example:
method Cyborg.Walk(pPace);
pPace > 0;
  pPace < 100;
FEnergyLevel >= 10;
ASP Classic:  "Code Contracts" Not Supported


[Other Languages] 

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

Delphi Prism:  "Constructors" constructor + class name

In Prism, a constructor is called whenever a class or struct is created. You use the constructor keyword with an unnamed method. You can overload the constructor simply by adding two or more unnamed methods with various parameters.

Prism also supports a Create constructor method for backward compatibility with Delphi for Win32.

If you do not create a constructor, Prism will create an implicit constructor that initializes all member fields to their default values.

Constructors can execute at two different times. Static constructors are executed by the CLR before any objects are instantiated. Regular constructors are executed when you create an object.

Syntax Example:
Cyborg = public class
  constructor(pName: String);
ASP Classic:  "Constructors" Class_Initialize

When an object instance is created from a class, ASP calls a special parameter-less sub named Class_Initialize. Since you cannot specify parameters for this sub, you also cannot overload it.

When a class is destroyed, ASP calls a special sub called Class_Terminate.

Syntax Example:
Class Cyborg
  Public CyborgName
 Public Sub Class_Initialize
   Response.Write "<br>Class created"
   CyborgName = "Cameron"
  End Sub 
End Class


[Other Languages] 

General Info: Class Destructor

A special class method called when an object instance of a class is destroyed. With some languages they are called when the object instance goes out of scope, with some languages you specifically have to call the destructor in code to destroy the object, and others use a garbage collector to dispose of object instances at specific times.

Desctructors are commonly used to free the object instance but with languages that have a garbage collector object instances are disposed of when appropriate. Either way, destructors or their equivalent are commonly used to free up resources allocated in the class constructor.

Languages Focus

Are object instances freed with a garbage collector? Or, do you have to destroy object instances.

Delphi Prism:  "Finalizer" finalize()

Unlike Delphi, Delphi Prism uses the .Net garbage collector to free managed object instances. Prism does not have nor need a true destructor.

In .Net, a finalizer is used to free non-managed objects such as a file or network resource. In Prism, you use the keyword finalizer to indicate the method is a finalizer. Each class can implement one and only one finalizer with a method name of finalize(), which is the method name used in Java and VB.Net.

Because you don't know when the garbage collector will call your finalizer, For non-managed resources, Microsoft recommends you implement the IDisposable interface and call it's Dispose() method at the appropriate time.

Syntax Example:
  Cyborg = class(IDisposable)
    disposed: Boolean;
    method Dispose(disposing: Boolean);
    method Dispose;
    finalizer Finalize;
ASP Classic:   Class_Terminate

When an object instance is destroyed, ASP calls a special parameter-less sub named Class_Terminate. For example, when the variable falls out of scope. Since you cannot specify parameters for this sub, you also cannot overload it.

To explicitly destroy an object, use Set YourClass = nothing. If the Class object is explicitly destroyed, the client returns with the script engine error details.

When an object instance is created from a class, ASP calls a special sub called Class_Initialize.

Syntax Example:
Class Cyborg
  Public Sub Class_Terminate
    Response.Write "<br>Class destroyed"
End Sub
End Class


[Other Languages] 
Delphi Prism:   Not Supported
ASP Classic:   Not Supported


[Other Languages] 

An element of coding where you define a common set of properties and methods for use with the design of two or more classes.

Both interfaces and abstract classes are types of abstraction. With interfaces, like abstract classes, you cannot provide any implementation. However, unlike abstract classes, interfaces are not based on inheritance. You can apply an Interface to any class in your class tree. In a real sense, interfaces are a technique for designing horizontally in a class hierarchy (as opposed to inheritance where you design vertically). Using interfaces in your class design allows your system to evolve without breaking existing code.

Delphi Prism:  "Interfaces"

With Prism, you use the Interface keyword to define an interface and then you include one or more interfaces where you specify the single class inheritance (separated by commas).

Syntax Example:
//Interface section of unit.
IHuman = public interface
//Specify interface methods and properties here.

TCyborg = public class
TCyborgHuman = public class(TCyborg, IHuman)
//Specify each here and implement in
//implementation section.
ASP Classic:  "Interfaces" Not Supported

Although ASP Classic does support simple classes, it does not support interfaces.


[Other Languages] 

General Info: Method Overriding

Where you define or implement a virtual method in a parent class and then replace it in a descendant class.

When you decide to declare a method as virtual, you are giving permission to derived classes to extend and override the method with their own implementation. You can have the extended method call the parent method's code too.

In most OO languages you can also choose to hide a parent method. When you introduce a new implementation of the same named method with the same signature without overriding, you are hiding the parent method.

Delphi Prism:   virtual, override

Same as Delphi. In Prism, you specify a virtual method with the virtual keyword in a parent class and extend (or replace) it in a descendant class using the override keyword. Call Inherited in the descendant method to execute the code in the parent method.

Use final to prevent further extending of a member and Sealed to prevent all members of a class from further extension.

Syntax Example:
Robot = class(System.Object)
method Speak; virtual;
Cyborg = class(Robot)
method Speak; override;
ASP Classic:   Not Supported

Since ASP Classic does not support inheritance, there is no concept of a descendant class nor overriding.

Partial Class

[Other Languages] 

A partial class, or partial type, is a class that can be split into two or more source code files and/or two or more locations within the same source file. Each partial class is known as a class part or just a part. Logically, partial classes do not make any difference to the compiler. The compiler puts the class together at compile time and treats the final class or type as a single entity exactly the same as if all the source code was in a single location.

Languages Focus

For languages that have implemented partial classes, you need to know usage details and restrictions. Can you split a class into two or more files? Can you split a class within a source code file into two or more locations? What are the details of inheritance? Does it apply to interfaces as well?

Delphi Prism:  "Partial Classes" partial

Prism supports both partial classes and partial methods using the keyword partial. A partial method is an empty method defined in a partial class.

Syntax Example:
//Organize a large class in multiple files.
T800 = partial class(Cyborg, IHuman);
T800 = partial class(ITalk);
//Partial methods too:�
T800 = public partial class
method Walk; partial; empty;
method Run; partial; empty;
ASP Classic:  "Partial Classes" Not Supported


[Other Languages] 

A coding technique where the same named function, operator, or object behaves differently depending on outside input or influences. Usually implemented as parameter overloading where the same named function is overloaded with other versions that are called either with a different type or number of parameters. Polymorphism is a general coding technique and other specific implementations are common such as inheritance, operator overloading, and interfaces.

Languages Focus

Many languages support built-in polymorphism such as a "+" operator that can add both integers and decimals. The following documents the ability to implement developer defined polymorphism.

Delphi Prism: 

Prism supports the following types of polymorphism:

More Info / Comment
[Not specified yet. Coming...]

Prevent Derivation

[Other Languages] 

Languages Focus

How do you prevent another class from inheriting and/or prevent a class from overriding a member.

Delphi Prism:   sealed, final

Same keywords as Delphi (sealed uses slightly different syntax). With Prism, use the sealed keyword before the class keyword to prevent a class from being inherited from and use the final keyword to prevent a method from being overridden.

Syntax Example:  
  Robot = public sealed class(System.Object) 
method Speak(pSentence: String); virtual; final;
ASP Classic:   Not Supported

Static Member

[Other Languages] 

General Info: Static Class / Static Member

A static member is a member you can have access to without instantiating the class into an object. For example, you can read and write static properties and call static methods without ever creating the class. Static members are also called class members (class methods, class properties, etc.) since they belong to the class and not to a specific object. A static class is a class that contains only static members. In the UML, these classes are described as utility classes.

Languages Focus

Languages that support static members usually at least support static member fields (the data). Some languages also support static methods, properties, etc. in which case the class member is held in memory at one location and shared with all objects. Finally, some languages support static classes which usually means the compiler will make sure a static class contains only static members.

Delphi Prism:  "Class Members" static

In Prism, you static members are also referred to as class members. You implement class members using the static keyword.

ASP Classic:  "Static Members" Not Supported

Although ASP Classic supports the creation of simple classes, it does not support static methods.

Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2022 Prestwood IT Solutions.   [Security & Privacy]