A
Alex Stevens
Well, It's 4:10 on Friday Afternoon and I am now in a state of
turmoil.......
I've just spoken with a trainer (who's opinion would be in far higher regard
than mine), and he's just told me that the way I expected to write an tiered
application is tight-coupled and should be written loosely coupled..........
I am kind of new to multi-tier application programming, although I have good
experience of classes, and objects.
I will attempt to describe my dilemma in the case of a Customer object:
-------Tight Coupled Method-------
I wanted to write a customer class which directly correlated to a customer
table (for ease of description). It would have a CustomerName and a phone
number property. It would have a save method which would write any changed
properties into the database (via a datalayer) and a get method which would
accept a customerID and populate the properties.
In my GUI, to get customer information I would insantiate a customer class
and call the get method passing the customer ID. I could then interogate the
customer properties to the customer name, and populate a text box.
If the user changed the text box, when they click a save button I would
write the textbox value back to the CustomerName property and then call the
save method.
-------Loose Coupled Method-------
The suggested method is to have my customer class, and all data is passed
around using arguments of get and save methods.
The class would have no properties, just a methods: A Get method which has a
(strCustomerName as string) arguement and likewise for the Save method, and
some others for reading (CRUD, Create, Read, Update, Delete....although I'm
sure I don't need to tell you that).
If my customer had even 10 fields this would be cumbersome, then the trainer
said you could pass back an array of values - but then surely this would
have to be order everytime.
In my (limited) mind, I don't understand why the tight coupled method is
bad??
Can somebody clarify this with their opinion on this........?
Thanks
Alex
turmoil.......
I've just spoken with a trainer (who's opinion would be in far higher regard
than mine), and he's just told me that the way I expected to write an tiered
application is tight-coupled and should be written loosely coupled..........
I am kind of new to multi-tier application programming, although I have good
experience of classes, and objects.
I will attempt to describe my dilemma in the case of a Customer object:
-------Tight Coupled Method-------
I wanted to write a customer class which directly correlated to a customer
table (for ease of description). It would have a CustomerName and a phone
number property. It would have a save method which would write any changed
properties into the database (via a datalayer) and a get method which would
accept a customerID and populate the properties.
In my GUI, to get customer information I would insantiate a customer class
and call the get method passing the customer ID. I could then interogate the
customer properties to the customer name, and populate a text box.
If the user changed the text box, when they click a save button I would
write the textbox value back to the CustomerName property and then call the
save method.
-------Loose Coupled Method-------
The suggested method is to have my customer class, and all data is passed
around using arguments of get and save methods.
The class would have no properties, just a methods: A Get method which has a
(strCustomerName as string) arguement and likewise for the Save method, and
some others for reading (CRUD, Create, Read, Update, Delete....although I'm
sure I don't need to tell you that).
If my customer had even 10 fields this would be cumbersome, then the trainer
said you could pass back an array of values - but then surely this would
have to be order everytime.
In my (limited) mind, I don't understand why the tight coupled method is
bad??
Can somebody clarify this with their opinion on this........?
Thanks
Alex