Re: Critique of Robert C. Martin's "Agile Principles, Patterns, and Practices"



On 2007-01-24 01:35:40 -0600, frebe73@xxxxxxxxx said:

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...

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?

Then I would hide that SQL statement behind an interface so that the rest of my application was unaware of it.


though fewer than the number of
embedded SQL statements that would exist if I did not put them behind
an interface.

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();

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...

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.

A much better idea would be to create a view
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.

Agreed. However, it is not a "much better idea" it is a better way of *implementing* the original idea. My aplication still needs the function. You've just provided a better way to implement it.

In any application, OO or not, [a] translation must take place.

Absolutely not.

The data is on the disk.

This is a common statement from people that lacks education about
modern databases. They think that the SQL statement
"select mycol from mytable", will cause the database to read something
from disk. In a well-tuned database, the data will most likely already
be in RAM.

<eye roll>
Really? Gosh! I didn't know that!
</eye roll>


It must be translated into some kind of
TableRow structure or similar.

You don't need a TableRow instance, just use select/fetch into. And if
you still prefer a result set, this class is generic. You don't have to
write it yourself.

Great! Then I can pass the convenient data structure around my application just like an object. How convenient!

If you have five variants of getEmployeeBySomeCriteria,
you obviously have duplication.
I don't see that at all. The five functions may simply call a more
general function passing in specific parameters.

Why do you want the five functions in the first place?

So I can give them meaningful names.

--
Robert C. Martin (Uncle Bob)  | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |



.



Relevant Pages

  • Re: MD5 question
    ... I have a database of employee information used at a company I ... > I have a SSN field with of course each employee's SSN. ... > that two different SSN's would generate the same MD5 hash? ...
    (sci.crypt)
  • Re: How to ID a record
    ... Is it conceivable that this database will ever have to handle a person ... without a SSN ... vehicle to vehicle. ... if the CarLog table stores which employee had which car on which day, ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Reviewing my code. Displaying a BLOB image through a browser
    ... "You need to write the sql statement to Response and look at ... What do you need to know about the database? ... person takes a picture of the employee and then fills out a few generic ... Set objConn = Server.CreateObject ...
    (microsoft.public.inetserver.asp.db)
  • duplicating info into multiple tables (one form)
    ... I have an existing database in use by a specific department to track errors ... employee info into this db, namely their employee name, id#, phone extension, ... I have database X with table A containing fields: name, id, SSN, phone# ...
    (microsoft.public.access.tablesdbdesign)
  • Re: ADO DBGrid Query Problem
    ... I have a database with an employee table. ... I want to create a recorset that shows the duplicate records. ... In Access 2000 I created a SQL statement that did display what I wanted. ...
    (microsoft.public.access.queries)