Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: frebe73@xxxxxxxxx
- Date: 26 Jan 2007 09:42:52 -0800
How many getEmployeeBySomeCriteria methods do you think you will end up
with in a normal payroll application?
I imagine it will be quite a few,
Only a few ways of fetching employees? By name, by employment no, by
SSN, by department, by city.... But I guess that you will do it the OO
way, fetching all employees and select the instances you really want,
by traversing them and call a matcher/filter function. Performance is a
secondary issue.
Who would do a dumb-ass thing like that? Sorry for the vulgarity but...
When I encounter this type of implementations, the main reason is
because they want to limit the number of getEmployeeBySomeCriteria
methods. Another reason is because they want to work with an objects
graphs instead of relational calculus.
No, of course I would use the database to fetch the data I want. I'd
make sure that a well structure SQL statement was used against a
well-normalized database. Who wouldn't?
You claim that it is possible to only have a few number of
getEmployeeBySomeCriteria methods with optimized SQL statements for
every different way you might need to fetch employee data? That should
only be possible for rather small applications.
Then I would hide that SQL statement behind an interface so that the
rest of my application was unaware of it.
And the benifits are?
What is the purpose with putting a statement like "select salary from
employee where SSN=?" behind an interface? You are substituting one
one-liner with another one-liner that needs an additional
implementation.Consider this:
Select employee_number from employee where date_of_birth < 1952 and sex
= F and employment_type = EXEMPT OR emloyment_type = SPECIAL and salary > 90000;
I'd like to hide this behind:
find_all_employees_eligible_for_early_retirement();
This should obviously be a view. After creating that view you might use
it in other queries.
select date, amount from payment p join
employee_eligible_for_early_retirement e on p.id=e.id
Your solution would cause extra roundtrips to the database for fetching
the same data.
Firstly, it makes the program easier to understand. Secondly, it
isolates the policy from the implementation. I can change the
implementaiton of the SQL statement without affecting the functions
that call find_all_employees...
A view would have the same benefits.
is more evocative than a long SQL statement that doesn't mention
retirement at all. Think of the functions as compilable comments that
describe what the SQL beneath them is intended to do.
Why do you ignore the existance of views?
A much better idea would be to create a viewAgreed. However, it is not a "much better idea" it is a better way of
EmployeesEligibleForRetirement. Views are much more flexible than
functions, because they can be combined together in other set
operations and logic statements. You might for example join this view
with the SalarayPayment relation. If you embedd the statement inside a
function, you don't have that kind of flexibility.
*implementing* the original idea. My aplication still needs the
function.
Your application does not need the function. Just call
select * from employee_eligible_for_early_retirement
Great! Then I can pass the convenient data structure around myIt must be translated into some kind ofYou don't need a TableRow instance, just use select/fetch into. And if
TableRow structure or similar.
you still prefer a result set, this class is generic. You don't have to
write it yourself.
application just like an object. How convenient!
There is no need for passing data structures around the application.
Relations are the only needed data structures. (Sometings performance
issues might force you to use low-level collection classes likes arrays
and hastables, but this is normally not the fact for business
applications.) The application should ask the database for the needed
data, using set theory and predicates, when the data is needed, not
before.
Fredrik Bertilsson
http://mybase.sf.net
.
- Follow-Ups:
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Robert Martin
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Thomas Gagne
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- References:
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: JXStern
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: topmind
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Robert Martin
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: topmind
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Robert Martin
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: frebe73
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Robert Martin
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: frebe73
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- From: Robert Martin
- Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- Prev by Date: OO is the new Go-To (was: Biz Tree Challenge)
- Next by Date: Use Case problem
- Previous by thread: Re: Wrapping SQL (Was: Critique of Robert C. Martin's...)
- Next by thread: Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"
- Index(es):
Relevant Pages
|