Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic new and inheritance
    primarykey
    data
    text
    <p><a href="http://msdn.microsoft.com/en-US/library/aa594035%28v=ax.10%29" rel="nofollow">Best Practices</a> recommend setting the new method as protected and using instead static new... methods to mitigate the lack of method overloading.<br> So I use this pattern as explained <a href="http://www.artofcreation.be/2010/05/18/creating-a-class-the-best-practice-way/" rel="nofollow">here</a></p> <p>But static methods are not inherited. So we have to define for each sub class the static construct and the static new... methods.<br> Therefore we lose some of inheritance's benefits.</p> <p>I had a look on system classes hoping to find a better solution but what I saw did not really help me :<br> - some respect the static new pattern and declare the methods in the sub classes<br> - some just use the instance new without protecting it<br> - some use the mother class as a "class factory", like SalesFormLetter</p> <pre><code>static SalesFormLetter construct(DocumentStatus document, boolean getParmId = true) { switch(document) { case DocumentStatus::Confirmation : return new SalesFormLetter_Confirm (getParmId); case DocumentStatus::PickingList : return SalesFormLetter_PickingList::construct(getParmId); case DocumentStatus::PackingSlip : return new SalesFormLetter_PackingSlip (getParmId); case DocumentStatus::ProjectPackingSlip : return new SalesFormLetter_PackingSlipProject(getParmId); case DocumentStatus::Invoice : return new SalesFormLetter_Invoice (getParmId); case DocumentStatus::ProjectInvoice : return new SalesFormLetter_InvoiceProject (getParmId); default : throw error(strfmt("@SYS19306",funcname())); } throw error(strfmt("@SYS19306",funcname())); } </code></pre> <p>So I am wondering if there is a better solution, and if not what would be the best among these ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload