Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 16th, 2009, 09:11 PM
Registered User
 
Join Date: Nov 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Defining a class member with the public access specifier

Under Chapter 10 > "How the Property Methods Work", the final paragraph in the subsection goes:

"Notice that, if you had defined the class member named current with the public access specifier, you could not do this kind of checking on current before it was used."

I don't remember any previous explicit explanation on this, and can't get my head 'round it. Could someone elaborate, please? I'd be most grateful, and then there'd be nothing so far that I haven't completely understood from the book.

"this kind of checking" refers to returning "current.Month" for a getter.
  #2 (permalink)  
Old December 17th, 2009, 10:51 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Access specifier

It would help a lot if you could give me the page number and then the paragraph where the quote is found...I had a late night last night...
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
  #3 (permalink)  
Old December 17th, 2009, 11:22 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Access specifier

Found it! (Page 240, second to last paragraph.)

I think the confusion arises because I refer back to a data definition in Chapter 9. If you look on page 225, you will see the statement:

private DateTime current;

which defined current as a private property within the clsDates object. In Chapter 10, you learn that setter and getter property methods are the proper way to change the value of a property within a class. This forces the programmer to use the code you write to change the state of any clsDates object the programmer instantiates.

If we don't use the private access specifier on current, you have no control over what gets assigned into current. By using the private access specifier on current, any time you change any aspect of the date (e.g., month, day, or year), you have the opportunity of checking what the user is trying to assign into the property. On page 240, for example, if the programmer is trying to assign a value into month, your code has the opportunity to insure that its value is reasonable (i.e., 1 to 12). If you make current a public property, you have no control over what gets assigned into current. The public access specifier turns your pristine piece of data into a prostitute that anyone can have their way with...not good. There are few reasons (none?) for making a class property method public, since you, by definition, lose some ability to check what gets assigned into that property. While there may be a few reasons for public properties, there aren't too many good ones. As a rule, make your property methods private and use getters and setters to gain better control over those properties.

I hope this helps...
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
  #4 (permalink)  
Old December 21st, 2009, 12:19 PM
Registered User
 
Join Date: Nov 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default

It helped wonders, thanks Dr. Purdum! I'm not even sure anymore why I could not get what you meant the first time through. It makes perfect sense now, I don't think I could even blame it on the wording of the original text, maybe I just needed some time and your help to sink the knowledge in.

Sorry I couldn't provide the page number, it's because I bought the Kindle version (working great on Kindle for PC) so it wouldn't be consistent.

Thanks again!
  #5 (permalink)  
Old December 21st, 2009, 12:40 PM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Kindle version

Glad things are clearer now. Also, I'm happy to hear that you're doing okay with the Kindle version. About the only bad review my book's received was because Kindle was giving him problems...hopefully that's history now.

Keep plugging away and enjoy the ride!
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining controls from a different class VB josh2009 Beginning VB 6 1 September 15th, 2009 09:54 PM
disadvantages of protected access specifier kishore.dyn Java Basics 2 August 10th, 2006 03:31 PM
Arraylist::Sort() by class member jilly Visual C++ 2005 0 March 22nd, 2006 06:49 PM
How to Assign a Desc. to a Class Member BrianWren VB.NET 2002/2003 Basics 3 June 1st, 2005 02:07 PM
How to make a class public johnjonsson VS.NET 2002/2003 0 October 6th, 2003 02:17 PM



All times are GMT -4. The time now is 04:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.