Beware Of Using Get And Set Codes Arizona

There is no doubt computer code writing is a tough job, you need to be careful when doing that job. Read the article below to learn tips for using"get" And "set".

Local Companies

JDR Consulting
480-491-4756
1660 S. Alma School Rd. Ste 223
Mesa, AZ
Aya Solutions
480-833-1727
1955 E Hackamore St
Mesa, AZ
Multi Edit Software Inc
480-610-2700
7532 E Dulciana Cir
Mesa, AZ
Alphasource Technologies Inc Inc
520-620-6888
3120 W Corte Olivia
Tucson, AZ
Component Software Inc
480-496-9303
5831 W Kesler St
Chandler, AZ
Synapps LLC
(480) 664-6071
4649 E Carriage Ct
Gilbert, AZ
Vertex Inc
(480) 283-8600
2961 E Marlene Dr
Gilbert, AZ
Wizard Computer Services
(480) 926-3144
2104 E Freeport Ln
Gilbert, AZ
Lone Wolf Software Inc.
(623) 824-1140
6097 N 57th Drive
Glendale, AZ
BBB Systems, LLC
(602) 424-0914
2340 W. Mission
Phoenix, AZ

It’s an all-too-common pitfall. Programmers who attempt to write object-oriented code decide to make all of their data variables private, while creating public get() and set() function pairs for each one. “See?” they declare, as they pat themselves on their backs. “The data is private, but it can be accessed through these functions. I’ve encapsulated my data. That’s what object-oriented design requires.”

I think this betrays a fundamental (and exceedingly common) misunderstanding of what constitutes encapsulation and information hiding. Ideally, in an object-oriented design, the user of a software class should have no idea what type of data the class contains. As far as he’s concerned, the class should simply provide the required services, and its internal details should be invisible. However, when we provide get() and set() function pairs for each member variable, we are basically announcing the existence of this data to the world. The information hiding provided by this class is weak—and arguably non-existent. One might change the name, data type or implementation of this member variable, but its existence remains painfully obvious to everyone.

(Note that I say that the user should “ideally” be oblivious to the type of data contained within the class. In practice, this is not always feasible. If we were to implement a BankAccount class, for example, most programmers would immediately guess that this class would have the account balance as one of its data members. They would also guess—rightfully so—that the owner of this account is likely to be data member as well. Nevertheless, we should avoid needlessly divulging such details, especially when the contents of a class are not so easily discerned.)

In effect, these get() and set() member functions are almost as bad as having public data. Sure, they may provide some useful services; for example, the set() function could validate the data, ensuring that it is within the proper range of values. Nevertheless, they tend to violate the spirit of information hiding, at least to some degree.

Using get() and set() functions is not always a bad idea; in fact, sometimes they make perfect sense. Their frequent use, however, is a pretty good indication of a poorly abstracted software design—one that does not adhere well to the principle of information hiding. When designing software classes, we need to think primarily in terms of the services they provide (i.e. their public functions), rather than the data they contain. Ideally, their data implementations should proceed from the required services, rather than other way around.

To illustrate this concept, let us revisit the BankAccount class mentioned earlier. It is clear that the BankAccount object will need to keep track of its balance, so let’s make that a data member. A novice programmer (or one with a poor grasp of object orientation) may choose to provide both GetBalance() and SetBalance() functions for this class… but does this make sense?

What happens when a user attempts to make a deposit? The user would have to call GetBalance(), add the deposit amount, and then set the new value using GetBalance(). That’s not how real users operate, though; in the real world, there is no need for the depositor to know how much money is in the account. This class design gives the user too much information and requires too many steps.

Similarly, to perform a withdrawal, the user would need to call GetBalance(), subtract the withdrawal amount, and then call SetBalance() to update the account. This also requires too much work on the user’s part. In the real world, the user should not always be required to know exactly how much money is in the account. This person might want to know that there are sufficient funds, but he wouldn’t necessarily need to know the precise balance, and this information should not be a constant requirement.

A sensibly written class should provide the following services instead: DepositAmount(), WithdrawAmount() and GetBalance(). With this design, the data member—the account balance—is logically implied by the services provided, rather than the other way around. (We could define other services, such as AccrueInterest() and TransferFunds(), but let’s keep it simple for now. Note that these services might suggest additional data members; for example, AccrueInterest() would suggest that a data member would be needed for the interest rate.)

In summary, get() and set() function pairs are not inherently bad, but their preponderance could suggest a poorly abstracted software design. There’s nothing inherently wrong with using get() and set() functions when they form part of a sensibly designed set of services. Nor is there anything wrong with using a data member to reflect these functions. When one proceeds in the opposite direction, though—when one starts with the data members, then adds corresponding get() and set() pairs—that’s a strong indication of a poorly conceived software design.

About the Author:

V. Berba Velasco Jr., Ph.D. is a senior electrical and software engineer at CTL (http://www.elispot-analyzers.de, http://www.immunospot.com, http://www.elispot.cn, http://www.elispot.co.jp), a biotech firm that provides ELISPOT technology, cryopreserved PBMCs and serum-free media.






Article Source:

thePhantomWriters Article Submission Service

Featured Local Company

JDR Consulting

480-491-4756
1660 S. Alma School Rd. Ste 223
Mesa, AZ
http://www.jdrconsulting.com

Related Articles
- Win PC Defender Arizona
There are a plethora of phony security applications out there, and Win PC Defender is one of them. Though the name sounds like it is something from the Microsoft Corporation, this just isn't the case. Buyer beware: Win PC Defender is a con game looking to swipe your money.
- Bioinformatics Introduction Arizona
- DVD ripping FAQ Arizona
- Using Lookup Tables in AppleWorks Arizona
- Antivirus And Security Arizona
- Regarding dumb Smart Folders Arizona
- Printing Software in Business Arizona
- CMMS Implementation Arizona
- How To Build A Flash Game Arizona
- Beating Spyware Arizona
Regional Articles
- Beware Of Using Get And Set Codes Apache Junction AZ
- Beware Of Using Get And Set Codes Avondale AZ
- Beware Of Using Get And Set Codes Buckeye AZ
- Beware Of Using Get And Set Codes Bullhead City AZ
- Beware Of Using Get And Set Codes Casa Grande AZ
- Beware Of Using Get And Set Codes Cave Creek AZ
- Beware Of Using Get And Set Codes Chandler AZ
- Beware Of Using Get And Set Codes Cottonwood AZ
- Beware Of Using Get And Set Codes Flagstaff AZ
- Beware Of Using Get And Set Codes Fountain Hills AZ
- Beware Of Using Get And Set Codes Gilbert AZ
- Beware Of Using Get And Set Codes Glendale AZ
- Beware Of Using Get And Set Codes Goodyear AZ
- Beware Of Using Get And Set Codes Green Valley AZ
- Beware Of Using Get And Set Codes Kingman AZ
- Beware Of Using Get And Set Codes Lake Havasu City AZ
- Beware Of Using Get And Set Codes Mesa AZ
- Beware Of Using Get And Set Codes Paradise Valley AZ
- Beware Of Using Get And Set Codes Peoria AZ
- Beware Of Using Get And Set Codes Phoenix AZ
- Beware Of Using Get And Set Codes Prescott AZ
- Beware Of Using Get And Set Codes Prescott Valley AZ
- Beware Of Using Get And Set Codes Safford AZ
- Beware Of Using Get And Set Codes Scottsdale AZ
- Beware Of Using Get And Set Codes Sedona AZ
- Beware Of Using Get And Set Codes Sierra Vista AZ
- Beware Of Using Get And Set Codes Somerton AZ
- Beware Of Using Get And Set Codes Sun City AZ
- Beware Of Using Get And Set Codes Sun City West AZ
- Beware Of Using Get And Set Codes Surprise AZ
- Beware Of Using Get And Set Codes Tempe AZ
- Beware Of Using Get And Set Codes Tucson AZ
- Beware Of Using Get And Set Codes Yuma AZ
Related Articles
- Win PC Defender Arizona
There are a plethora of phony security applications out there, and Win PC Defender is one of them. Though the name sounds like it is something from the Microsoft Corporation, this just isn't the case. Buyer beware: Win PC Defender is a con game looking to swipe your money.
- Bioinformatics Introduction Arizona
- DVD ripping FAQ Arizona
- Using Lookup Tables in AppleWorks Arizona
- Antivirus And Security Arizona
- Regarding dumb Smart Folders Arizona
- Printing Software in Business Arizona
- CMMS Implementation Arizona
- How To Build A Flash Game Arizona
- Beating Spyware Arizona
Related Local Events
The Big Draw VI
Dates: 12/1/2009 - 12/1/2009
Location: The Crown Room
Scottsdale, AZ
View Details

Toastmasters
Dates: 1/7/2010 - 1/7/2010
Location: Peoria Chamber of Commerce
Peoria, AZ
View Details

Toastmasters
Dates: 2/4/2010 - 2/4/2010
Location: Peoria Chamber of Commerce
Peoria, AZ
View Details

Toastmasters
Dates: 3/25/2010 - 3/25/2010
Location: Peoria Chamber of Commerce
Peoria, AZ
View Details

Toastmasters
Dates: 5/6/2010 - 5/6/2010
Location: Peoria Chamber of Commerce
Peoria, AZ
View Details

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Family Home Services Real Estate Resources
Business Services Fashion Industrial Goods & Services Retail & Consumer Services
Career Financial Services Insurance Software
Cars Food & Beverage Internet Technology
Computer Hardware Franchise Legal Telecommunications
Construction Health Miscellaneous Trade Shows
Education Holidays Nightlife Travel
Entertainment Home Appliances Online Database Weddings
Environmental Home Electronics Pets World History