Beware Of Using Get And Set Codes Michigan

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

Corporate IT Source
248-396-1573
6841 N. Rochester Rd.
Rochester Hills, MI
Cms Software
313-965-4775
500 Griswold St
Detroit, MI
Protocol Syst C
313-534-8773
18201 W 8 Mile Rd
Detroit, MI
All About Technology
313-962-2430
2727 2nd Ave
Detroit, MI
Computer Power Store
313-640-4681
15411 Mack Ave
Detroit, MI
L & M Office Products
313-861-5707
8514 W Mcnichols RD
Detroit, MI
Keane Inc
248-356-2000
3000 Northwestern St
Detroit, MI
Sync Technologies
313-963-5353
2727 2nd Ave
Detroit, MI
Woodwing USA
313-962-0542
615 Griswold St
Detroit, MI
PC Menders Computer Services
313-397-2713
18256 Grand River Ave
Detroit, MI

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

Corporate IT Source

248-396-1573
6841 N. Rochester Rd.
Rochester Hills, MI

Related Articles
Regional Articles
- Beware Of Using Get And Set Codes Adrian MI
- Beware Of Using Get And Set Codes Allegan MI
- Beware Of Using Get And Set Codes Allen Park MI
- Beware Of Using Get And Set Codes Alpena MI
- Beware Of Using Get And Set Codes Ann Arbor MI
- Beware Of Using Get And Set Codes Auburn Hills MI
- Beware Of Using Get And Set Codes Battle Creek MI
- Beware Of Using Get And Set Codes Bay City MI
- Beware Of Using Get And Set Codes Belleville MI
- Beware Of Using Get And Set Codes Benton Harbor MI
- Beware Of Using Get And Set Codes Berkley MI
- Beware Of Using Get And Set Codes Big Rapids MI
- Beware Of Using Get And Set Codes Bloomfield Hills MI
- Beware Of Using Get And Set Codes Brighton MI
- Beware Of Using Get And Set Codes Burton MI
- Beware Of Using Get And Set Codes Cadillac MI
- Beware Of Using Get And Set Codes Canton MI
- Beware Of Using Get And Set Codes Cheboygan MI
- Beware Of Using Get And Set Codes Clarkston MI
- Beware Of Using Get And Set Codes Clinton Township MI
- Beware Of Using Get And Set Codes Clio MI
- Beware Of Using Get And Set Codes Coldwater MI
- Beware Of Using Get And Set Codes Commerce Township MI
- Beware Of Using Get And Set Codes Comstock Park MI
- Beware Of Using Get And Set Codes Davison MI
- Beware Of Using Get And Set Codes Dearborn Heights MI
- Beware Of Using Get And Set Codes Dearborn MI
- Beware Of Using Get And Set Codes Detroit MI
- Beware Of Using Get And Set Codes Dowagiac MI
- Beware Of Using Get And Set Codes East Lansing MI
- Beware Of Using Get And Set Codes Eastpointe MI
- Beware Of Using Get And Set Codes Eaton Rapids MI
- Beware Of Using Get And Set Codes Escanaba MI
- Beware Of Using Get And Set Codes Farmington MI
- Beware Of Using Get And Set Codes Fenton MI
- Beware Of Using Get And Set Codes Ferndale MI
- Beware Of Using Get And Set Codes Flat Rock MI
- Beware Of Using Get And Set Codes Flint MI
- Beware Of Using Get And Set Codes Flushing MI
- Beware Of Using Get And Set Codes Fort Gratiot MI
- Beware Of Using Get And Set Codes Fraser MI
- Beware Of Using Get And Set Codes Garden City MI
- Beware Of Using Get And Set Codes Gaylord MI
- Beware Of Using Get And Set Codes Gladwin MI
- Beware Of Using Get And Set Codes Grand Blanc MI
- Beware Of Using Get And Set Codes Grand Haven MI
- Beware Of Using Get And Set Codes Grand Ledge MI
- Beware Of Using Get And Set Codes Grand Rapids MI
- Beware Of Using Get And Set Codes Grandville MI
- Beware Of Using Get And Set Codes Grosse Pointe MI
- Beware Of Using Get And Set Codes Hamtramck MI
- Beware Of Using Get And Set Codes Harper Woods MI
- Beware Of Using Get And Set Codes Harrison Township MI
- Beware Of Using Get And Set Codes Hazel Park MI
- Beware Of Using Get And Set Codes Highland Park MI
- Beware Of Using Get And Set Codes Hillsdale MI
- Beware Of Using Get And Set Codes Holland MI
- Beware Of Using Get And Set Codes Holly MI
- Beware Of Using Get And Set Codes Holt MI
- Beware Of Using Get And Set Codes Howell MI
- Beware Of Using Get And Set Codes Hudsonville MI
- Beware Of Using Get And Set Codes Inkster MI
- Beware Of Using Get And Set Codes Ionia MI
- Beware Of Using Get And Set Codes Jackson MI
- Beware Of Using Get And Set Codes Jenison MI
- Beware Of Using Get And Set Codes Kalamazoo MI
- Beware Of Using Get And Set Codes Lake Orion MI
- Beware Of Using Get And Set Codes Lansing MI
- Beware Of Using Get And Set Codes Lapeer MI
- Beware Of Using Get And Set Codes Lincoln Park MI
- Beware Of Using Get And Set Codes Livonia MI
- Beware Of Using Get And Set Codes Ludington MI
- Beware Of Using Get And Set Codes Macomb MI
- Beware Of Using Get And Set Codes Marquette MI
- Beware Of Using Get And Set Codes Midland MI
- Beware Of Using Get And Set Codes Monroe MI
- Beware Of Using Get And Set Codes Mount Clemens MI
- Beware Of Using Get And Set Codes Mount Morris MI
- Beware Of Using Get And Set Codes Mount Pleasant MI
- Beware Of Using Get And Set Codes Muskegon MI
- Beware Of Using Get And Set Codes New Baltimore MI
- Beware Of Using Get And Set Codes Niles MI
- Beware Of Using Get And Set Codes Northville MI
- Beware Of Using Get And Set Codes Novi MI
- Beware Of Using Get And Set Codes Oak Park MI
- Beware Of Using Get And Set Codes Okemos MI
- Beware Of Using Get And Set Codes Owosso MI
- Beware Of Using Get And Set Codes Petoskey MI
- Beware Of Using Get And Set Codes Pinckney MI
- Beware Of Using Get And Set Codes Plymouth MI
- Beware Of Using Get And Set Codes Pontiac MI
- Beware Of Using Get And Set Codes Port Huron MI
- Beware Of Using Get And Set Codes Portage MI
- Beware Of Using Get And Set Codes Redford MI
- Beware Of Using Get And Set Codes Rochester MI
- Beware Of Using Get And Set Codes Rockford MI
- Beware Of Using Get And Set Codes Romulus MI
- Beware Of Using Get And Set Codes Roseville MI
- Beware Of Using Get And Set Codes Royal Oak MI
- Beware Of Using Get And Set Codes Saginaw MI
- Beware Of Using Get And Set Codes Saint Clair Shores MI
- Beware Of Using Get And Set Codes Saint Johns MI
- Beware Of Using Get And Set Codes Saline MI
- Beware Of Using Get And Set Codes Sault Sainte Marie MI
- Beware Of Using Get And Set Codes South Haven MI
- Beware Of Using Get And Set Codes South Lyon MI
- Beware Of Using Get And Set Codes Southfield MI
- Beware Of Using Get And Set Codes Southgate MI
- Beware Of Using Get And Set Codes Sterling Heights MI
- Beware Of Using Get And Set Codes Sturgis MI
- Beware Of Using Get And Set Codes Swartz Creek MI
- Beware Of Using Get And Set Codes Taylor MI
- Beware Of Using Get And Set Codes Temperance MI
- Beware Of Using Get And Set Codes Three Rivers MI
- Beware Of Using Get And Set Codes Traverse City MI
- Beware Of Using Get And Set Codes Trenton MI
- Beware Of Using Get And Set Codes Troy MI
- Beware Of Using Get And Set Codes Utica MI
- Beware Of Using Get And Set Codes Walled Lake MI
- Beware Of Using Get And Set Codes Warren MI
- Beware Of Using Get And Set Codes Waterford MI
- Beware Of Using Get And Set Codes West Bloomfield MI
- Beware Of Using Get And Set Codes Westland MI
- Beware Of Using Get And Set Codes White Lake MI
- Beware Of Using Get And Set Codes Wixom MI
- Beware Of Using Get And Set Codes Wyandotte MI
- Beware Of Using Get And Set Codes Wyoming MI
- Beware Of Using Get And Set Codes Ypsilanti MI
- Beware Of Using Get And Set Codes Zeeland MI
Related Local Events
Real-Time & Embedded Computing Conference-Detroit (RTECC)
Dates: 9/17/2009 - 9/17/2009
Location: Sterling Inn Banquet & Conference Center, Detroit
Sterling Heights, MI
View Details

A&WMA CONFERENCE & EXHIBITION
Dates: 6/16/2009 - 6/19/2009
Location: Marriott Hotel Detroit, Detroit
Detroit, MI
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