S
shaanxxx
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
I try to explain through example
-> First implementation
Node * GetNextFile(ListState state)
{
... //common statements for file and directory processing
... // File specific statement
}
Node * GetNextDIR(ListState state)
{
... //common statements for file and directory processing
... // Directory specific statements
}
-> Second implementation
Node * GetNext(ListState state , NodeType type)
{
... //common statements for file and directory processing
if (type == FILE_TYPE)
{
... // File specific statement
}
else
{
... // Directory specific statements
}
}
Let me know your thoughts on this
I think if common processing statements are less , we can go first
implementation .
programme or one function with "if statement"
for two task having some part common.
I try to explain through example
-> First implementation
Node * GetNextFile(ListState state)
{
... //common statements for file and directory processing
... // File specific statement
}
Node * GetNextDIR(ListState state)
{
... //common statements for file and directory processing
... // Directory specific statements
}
-> Second implementation
Node * GetNext(ListState state , NodeType type)
{
... //common statements for file and directory processing
if (type == FILE_TYPE)
{
... // File specific statement
}
else
{
... // Directory specific statements
}
}
Let me know your thoughts on this
I think if common processing statements are less , we can go first
implementation .