DelphiFeeds.com

  • Dashboard
  • Popular Stories
  • Trending Stories
  • Feeds
  • Login
Trending now

Using Apilayer REST APIs from Delphi

Using Apilayer REST APIs from Delphi

7 Tips For Learning To Build Powerful Windows GUI Apps Using Python And Delphi

Create Enterprise-Grade Grid Based Desktop Applications 10x Faster With X-Files Components

Quickly Learn How To Fetch A Table Using FireDAC In This IFDPhysCommand Delphi Sample

Tutorial: Introduction To C++ Parallel Compilation With TwineCompile

Easily Integrate Exception Handling Into Your Python GUI Apps Through Delphi

Delphi debugging tip: keep an eye on a object field of an object that will ...

Distinguer les processeurs Intel des processeurs Apple Silicon depuis nos programmes

Powerful Award-Winning Windows UI Toolkit For Delphi And C++Builder

Quickly Access Windows System Info In Your Delphi Application With Excellent Component Suite

Build Visual Stunning Apps Faster With Less Code Using RAD Studio Architect Edition

Introduction To Modern C++ With Tutorials

TMS WEB Core for Visual Studio Code v1.2 released!

Quickly Learn About High-Performance Python Generators With A Delphi Windows GUI App

Do not make methods protected unless you want them to be visible as public

1
jpluimers jpluimers 2 months ago in Conference Topics, Conferences, Delphi, Development, Event, Software Development 0

One of the protection levels in Delphi is protected. Originally meant for the class itself, that level is also visible to “friends”: anything in the same unit, for example:

unit BusinessLogicUnit;

interface

type
  TBusinessLogic = class(TObject)
  protected
     Procedure Foo();
     // ...
  public
     // ...
  end;

implementation

// ...

end.

You can even access them from outside that unit by using a trick like below.

Some people use the protected section so that unit tests can assess them using the below trick.

Do not do that!

It means anyone can use that trick, often doing more damage than good.

In this case, the trick was abused by a clever programmer that was relatively new to the code base. It resulted in unintended side effects.

unit HackUnit;

interface

implementation

uses
  BusinessLogicUnit;

type
  TBusinessLogicHack = class(TBusinessLogic);

procedure Hack;
var
  Instance: TBusinessLogicHack;
begin
  Instance := TBusinessLogicHack.Create();
  try
    Instance.Foo();
  finally
    Instance.Free();
  end;
end;

end.

Of course you can still access it like below.

It is slightly longer, but more importantly: much better shows the intent and how that intent is accomplished.

unit GoodUsageUnit;

interface

implementation

uses
  BusinessLogicUnit;

type
  TBusinessLogicDescendant = class(TBusinessLogic)
  public
    procedure Foo();
  end;

procedure TBusinessLogicDescendant.Foo();
begin
  inherited Foo();
  // ...
end;

procedure Usage;
var
  Instance: TBusinessLogicDescendant;
begin
  Instance := TBusinessLogicDescendant.Create();
  try
    Instance.Foo();
  finally
    Instance.Free();
  end;
end;

end.

–jeroen

Trending Stories

  • Using Apilayer REST APIs from Delphi

  • 7 Tips For Learning To Build Powerful Windows GUI Apps...

  • Create Enterprise-Grade Grid Based Desktop Applications 10x Faster With X-Files...

  • Quickly Learn How To Fetch A Table Using FireDAC In...

  • Tutorial: Introduction To C++ Parallel Compilation With TwineCompile

Embarcadero GetIt

  • Brook Framework

    Microframework which helps to develop web Pascal applications.

  • Trial - TMS Scripter

    Add the ultimate flexibility and power into your apps with native Pascal or Basic scripting and […]

  • Trial - TMS VCL Chart

    DB-aware and non DB-aware feature-rich charting components for business, statistical, financial […]

  • Trial - TMS VCL Cloud Pack

    TMS VCL Cloud Pack is a Delphi and C++Builder component library to seamlessly use all major cloud […]

  • Trial - TMS VCL UI Pack

    Create modern-looking & feature-rich Windows applications faster with well over 600 components […]

  • Learn Delphi Programming
  • Learn C++
  • Embarcadero Blogs
  • BeginEnd.net
  • Python GUI
  • Firebird News
  • Torry’s Delphi Pages
Copyright DelphiFeeds.com 2021. All Rights Reserved
Embarcadero
Login Register

Login

Lost Password

Register

Lost Password