Delphi: Record constructor vs factory function

后端 未结 4 2012
再見小時候
再見小時候 2021-02-12 20:25

So what will be the preferred way of initializing records?

With a \'factory function\':

TMyRecord = record
  valueX: integer;
  valueY: integer;
end;

fu         


        
4条回答
  •  孤独总比滥情好
    2021-02-12 20:53

    I'd prefer "factory method" like

      function TMyRecord.CreateRec(const AValueX, AValueY: integer): TMyRecord;
    

    Separate factory function leaks incapsulation and record constructors just confuse IMHO.

提交回复
热议问题