Skip to content

Make TCSSSelector.AddProperty fluent #73

Closed
@delphidabbler

Description

@delphidabbler

procedure TCSSSelector.AddProperty(const CSSProp: string);

Convert TCSSSelector.AddProperty to be fluent and to return its Self instance to enable chained method calls.

Presently, this method is usually called in with statements. That's a code smell that would best be refactoring out. Making this proposed change would make the proposed refactoring easier.

For example, refactoring

with CSSBuilder.AddSelector('a.command-link') do
begin
  AddProperty(TCSS.ColorProp(clCommandLink));
  AddProperty(TCSS.FontStyleProp(cfsItalic));
  AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;

Without the proposed change would result in something like:

var
  Sel: TCSSSelector;
begin
  Sel := CSSBuilder.AddSelector('a.command-link');
  Sel.AddProperty(TCSS.ColorProp(clCommandLink));
  Sel.AddProperty(TCSS.FontStyleProp(cfsItalic));
  Sel.AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;

While with the fluent version we could write

begin
  CSSBuilder.AddSelector('a.command-link')
    .AddProperty(TCSS.ColorProp(clCommandLink))
    .AddProperty(TCSS.FontStyleProp(cfsItalic))
    .AddProperty(TCSS.TextDecorationProp([ctdNone]));
end;

Which doesn't require a local variable and is more readable.

Metadata

Metadata

Assignees

Labels

completedWork has been completed on this issue and changes have been committed to `develop` branch..refactoringThis issue requires refactoring only, not a change in functionality

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy