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