If let's say we have a parent class for posting journals
Table1post
and we have other child classes that extend it, like
Table1Post_JournalType1, Table1Post_JournalType2, Table1Post_JournalType3, Table1Post_JournalType4...etc
Now i have a logic that is common between JournalType1 and JournalType2 only -- so what is better to put the logic in each class of those journal types or to put it in parent class and put if conditon for those two types only? or a new class for all of this?
Here's what I did:
final class Table1Post_Extension
{
{
if (!_table1 || _table1.Enum1 == NoYes::Yes)
{
return false;
}
{
case JournalType::JournalType1:
return this.parmCreateOrder();
return this.isPreviousJournalType1WithoutOrder(_table1);
}
return false;
}
{
str IdNext;
TableSetup tableSetup = TableSetup::find(_table1.CustAccount);
if(tableSetup.IdPrefix)
{
if(this.canJournalGenerateId(_table1))
{
Table1 table1ParmId;
select count(RecId) from table1ParmId
where table1ParmId.JournalParmId == _table1.JournalParmId;
if(table1ParmId.RecId == 1)
{
int lastNum;
str lastDeliveryNumberSeqFormat;
str dLastCreated = Table1::IdLastCreated(_table1.CustAccount, _table1.JournalType);
//logic
}
}
}
{
//logic
}
//child class 1
final class Table1Post_JournalType1_Extension
{
void postPosting(Table1 _table1)
{
Table1 table1Update = _table1;
str IdNext = this.generateId(_table1);
if(IdNext)
{
ttsbegin;
table1Update = Table1::find(_table1.JournalId, true);
table1Update.Id = IdNext;
table1Update.update();
ttscommit;
}
}
{
next initTableX(_table1, _tableX);
{
_tableX.Id = _table1.Id;
}
}}
//child class 2
final class Table1Post_JournalType2_Extension
{
void postPosting(Table1 _table1)
{
Table1 table1Update = _table1;
str IdNext = this.generateId(_table1);
if(IdNext)
{
ttsbegin;
table1Update = Table1::find(_table1.JournalId, true);
table1Update.Id = IdNext;
table1Update.update();
ttscommit;
}
}
{
next initTableX(_table1, _tableX);
{
_tableX.Id = _table1.Id;
}
}
[ExtensionOf(tableStr(Table1))]
final class Table1_Extension
{
public static str IdLastCreated(CustAccount _custAccount, JournalType _journalType)
{
if(_journalType == JournalType::JournalType1 || _journalType == JournalType::JournalType2)
{
str IdLastCreated = '';
&& Table1.createdDateTime < DateTimeUtil::addDays(todayDate, 1))
&& Table1.Posted == 1
&& Table1.CustAccount == _custAccount
&& (Table1.JournalType == JournalType::JournalType2
|| Table1.JournalType == JournalType::JournalType1 )).Id;
}
else
{
throw error(/error/);
}
}
How would I refactor the code to make it better? is the structure i did good from architecture and clean code point of view?

Report
All responses (
Answers (