An Abstract Example
The following demonstrates the abstract method above and also contains an abstract property (or rather, a regular property that makes use of abstract methods). The following main unit assumes a form with a button.
namespace CR_Abstraction;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Linq,
System.Windows.Forms,
System.ComponentModel;
type
///
/// Summary description for MainForm.
///
MainForm = partial class(System.Windows.Forms.Form)
private
method button1_Click(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
Cyborg = public abstract class(System.Object)
protected
//Abstract methods for property.
method GetCyborgName: String; abstract;
method SetCyborgName(Value: String); abstract;
public
//Abstract property, regular property that uses abstract methods.
property CyborgName: String read GetCyborgName write SetCyborgName;
method Speak(pMessage: String); abstract;
method Walk; virtual; abstract;
end;
Series600 = public class(Cyborg)
private
FCyborgName: String;
protected
method GetCyborgName: String; override;
method SetCyborgName(Value: String); override;
public
method Speak(pMessage: String); override;
method Walk; override;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
begin
var MyKiller: Series600;
MyKiller := New Series600;
MyKiller.CyborgName := 'John';
MyKiller.Speak('I am ' + MyKiller.CyborgName + '.');
MyKiller.Speak('I am alive.');
end;
method Series600.Speak(pMessage: String);
begin
MessageBox.Show(pMessage);
end;
method Series600.Walk;
begin
//Impliment walk here.
end;
method Series600.GetCyborgName: String;
begin
Result := FCyborgName;
end;
method Series600.SetCyborgName(Value: String);
begin
FCyborgName := Value;
end;
end.
Summary
Abstraction is an important aspect of your software design and Prism implements a robust set of abstract features. To learn more about how abstract classes are similar concepts to interfaces, how they relate to Plato's Forms theory, and more, read our Abstract Members / Class definition article next.