473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tight / Loose Coupling: What's the Idea?

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
(strCustomerNam e as string) arguement and likewise for the Save method, and
some others for reading (CRUD, Create, Read, Update, Delete....altho ugh 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

Nov 20 '05 #1
4 3317
"Alex Stevens" <al************ *************@g cc.co.uk> wrote...
Well, It's 4:10 on Friday Afternoon and I am now in a state of
turmoil...
I can imagine :-)
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...
From your descriptions I'd have to conclude a) the guy is trying out some
new idea he has come up with or b) you've misinterpreted what he said.

We're all familiar with the term loosely-coupled of course but I've never
heard it applied to the "property" level. One drawback of a generalized,
parameter-based Get/Set is that it is by necessity typeless. It cannot
return a string sometimes and an integer others. This generally makes the
plan "unworkable " because not all data can be represented by a string or any
single data type. The exception would be if it always accepted/returned an
object however.
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.


It just sounds plain goofy. If he is proposing something of any real value
he should be able to point to a document somewhere on the Internet that
explains the theory, it's benefits (and importantly) whatever it's downsides
are. All systems have a downside. Have him show you a simple working
example of a system written his way and have him point out the benefits over
having developed it the way you described in your tightly-coupled example.

Tom
Nov 20 '05 #2
yes, i agree with tom. it's ok to be practical.

p.s. who cares what a trainer thinks - there's a reason why he is a
trainer...
On Fri, 9 Jan 2004 11:49:15 -0500, "Tom Leylan"
<ge*@iamtiredof spam.com> wrote:
"Alex Stevens" <al************ *************@g cc.co.uk> wrote...
Well, It's 4:10 on Friday Afternoon and I am now in a state of
turmoil...


I can imagine :-)
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...


From your descriptions I'd have to conclude a) the guy is trying out some
new idea he has come up with or b) you've misinterpreted what he said.

We're all familiar with the term loosely-coupled of course but I've never
heard it applied to the "property" level. One drawback of a generalized,
parameter-based Get/Set is that it is by necessity typeless. It cannot
return a string sometimes and an integer others. This generally makes the
plan "unworkable " because not all data can be represented by a string or any
single data type. The exception would be if it always accepted/returned an
object however.
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.


It just sounds plain goofy. If he is proposing something of any real value
he should be able to point to a document somewhere on the Internet that
explains the theory, it's benefits (and importantly) whatever it's downsides
are. All systems have a downside. Have him show you a simple working
example of a system written his way and have him point out the benefits over
having developed it the way you described in your tightly-coupled example.

Tom


Nov 20 '05 #3
Alex,

First off, this is a very bad description of tight/loose coupling (from your
trainer). In fact, from the sound of it, your trainer is just starting to
learn OOP, probably from an old source. You can tell this because older
languages have no concept of a "Property", instead you use methods - usually
prefixed with "get_" or "set_" (which is essentially what a property in VB
is). Properties are actually an advancement in language design.

Dependencies are a necessary evil of programming, sure you could make all
variables global, or make them arrays, or whatever hack-of-the-day you want
to use, but the reality is that you are just generating more dependencies on
smaller objects. The idea is to *plan* your dependencies strategically, and
to group them logically - this is called Cohesion, which is a major goal of
any OO design.

Here is a common model for your customer problem (i have added dashes at the
tier boundaries):

----- Data Access:

DataTransport - Reads / Writes data to & from a data source (such as MSSQL
Server) - but never creates an instance of an app domain object (such as a
Customer object).

----- Business Logic:

DataAccessLogic Controller - Accepts & returns App-domain specific objects
(such as a Customer class), and converts them into commands that
DataTransport will send to your data server. DALC can also combine a group
of SQL commands to preform some sort of logical action on an object. DALC
has no binding to a *specific* data source.

----- Application Domain:

Model / Application Domain Objects - these objects hold your data that has
been loaded from the DALC, they can only hold references to other Model
objects (for example, the Customer can hold an instance of Address, but
never DALC or DataTransport).

----- View / View Logic:

View - the View holds an instance of Model, but never accesses it directly.
Instead, the view depends on either a Controller (see below), or events from
the Model that signal a change.

ViewController - the view controller CAN read & write data directly to the
Model, View, and DALC, but never DataTransport. The ViewController takes
gestures (key-presses, mouse clicks etc...) and converts them into logical
commands based on state.
_______________ _____________

So you could say that the SqlDataTranspor t is tightly coupled to SQLServer,
DALC is loosely coupled to generic DataTransport (not SqlDataTranspor t),
View is very loosely coupled to the Model, ViewController is tightly coupled
to View, and Model is not coupled to anything. Now, what is the point of all
this?

1. The Model is re-usable, you can pull the classes out, stick them in a new
project, and everything still works exactly as it did before (which is very
nice if you want to change the UI - i.e.. move the model from WinForms to
Web, or Hand-held devices).

2. The DataTransport can be changed at any time (ie. from SqlServer to MS
Access, or Oracle), and it won't send shock waves through your app. The
only thing effected is the Transport object, not even the DALC will be
effected if you code it right (which is very easy if you use the ADO.NET
Interface objects IDBxxxxx).

3. The Model can change, and the View will suffer limited damage, since the
View only has an indirect dependency.

(and on and on)

You may want to do you self a favor, and go get a book on OOP - "Design
Patterns" is the industry standard book, but it is an extremely hard read if
you are just getting into OOP. It sounds like your trainer may need one too.
An easy start may be to search for "Model View Controller" or "Model View
Presenter" on google.

Sorry about the long post.

HTH,
Jeremy

Nov 20 '05 #4
Hi Alex

I think that what you are asking for, is not well defined with the term Tight/Loose coupling, besides, that term has different interpretations . I think the "idea" your instructor tries to tell, is that a change in your app should have minimal impact in the rest of the system. Thats why we design APIs, interfaces, layers, tiers, servers or whatever, trying to isolate changes impact. And thats the idea in all system design regardless of language (ie OOP, procedural). You should design your system thinking that: you will need to update it as time pass. That restructuring your system to accomodate changes should be easy for you (that is a fast response to your customers). That distributing your updates should be easy, reliable and fast. That your system will have bugs, and your system should alert you so you can track and correct them. That your source code should be clear and documented, so when you need some other programmer to help you, he can do it fast. That, if you are going to design "tiers" that will run in separate machines, you should understand you are designing a server and what that means

I guess I can make the list very long... Welcome to the art of software engineering, system architecting, programming or whatevername this will be called in the next years

Good luck

Mariano.
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2399
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's not even relative with implementation - I'm looking for a smart solution My present system works like this:
14
2675
by: Daniel Chartier | last post by:
Hello. I work in the paper industry and we recently had someone (the original author) from within the company make a program for preventive maintenance. However, it had some bugs and we wanted to add stuff to it, bu tthe original author/programmer was leaving, so we called in a free agent programmer. The free agent spoke with the original programmer and myself for a day. He fixed afew bugs. For the other bugs and the many...
0
357
by: John Crowley | last post by:
I keep running into this over and over again... I want a block server control that renders a header and footer, and child controls in between. But I don't want a templated control, for the following reasons: 1) Render blocks are not allowed inside a templated control. 2) I want the inner controls scoped at the parent aspx (or ascx), not at the template naming container. This type of control would be ideal for website headers and...
2
1391
by: Steven T. Hatton | last post by:
I'm carrying on a discussion in a nother context regarding the value and usefulness of data types. Part of that discussion has to do with how data types might be implemented in the language specific to that context. I'm using C++ as an example for comparison and contrast. I believe I have a pretty go idea how data types work in C++, but I'm not sure I could enumerate a list of reasons for using types without giving it a lot of thought....
669
25859
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
11
2982
by: ctman770 | last post by:
Hi Everyone, Is it faster to save the precise location of an html dom node into a variable in js, or to use getElementById everytime you need to access the node? I want to make my application as fast as possible. I have about 10-20 id tags that need to be accessed and modified from time to time. Would the jvm perform slowly if I stored all of the dom node strings "document.node.child...." into a huge js array?
3
1054
by: Jan Theodore Galkowski | last post by:
Hi. One of the things I'd like to do with Python is find a way to consistently implement Smalltalk's "loose methods". This is a capability whereby additional methods can be added dynamically to existing classes. In some respects, it's possible with Python. While "object" cannot be touched, it's possible to define
3
1580
by: Andy B | last post by:
I have a complex object that is made up of 17 other objects and 2 dynamic dictionary collections. Would it be safe to say that I should possible make some sort of ObjectBuilder method in the main/root object to help contain the creation code? Or should it be broken up into smaller parts before the main builder method puts it all together? I know with something this huge, just putting out in loose code isn't a wise idea. What do you think?...
2
11919
by: Ronald S. Cook | last post by:
In trying to figure out how to make function MedicineClass.ApplyMedicinePriceChanges perform better, I ran Code Analysis and got the following: ****************************************************************************************** Warning 1677 CA1506 : Microsoft.Maintainability : 'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice, String, Guid, Decimal)' is coupled with 34 different types from 9...
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.