I.T. Discussion Community!
-Collapse +Expand
Coder
Search Coder Group:

Advanced
-Collapse +Expand Coder Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Coder Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBRole-Based T...Coding & OOObject Orien...   Print This     
  From the October 2009 Issue of Prestwood eMag
 
Coder Object Orientation (OO):
Member Field
 
Posted 11 years ago on 12/25/2008 and updated 9/20/2009
Take Away:

Also known as a Class Field.

A class variable defined with a specific class visibility, usually private visibility. A member property is different than a member field. A member property uses a member field to store values through accessor methods (getters and setters). For example, it is common to use a private member field to store the current value of a property. The current values of all the class member fields is the current state of the object.

Coder Definition Flashcard:
 A flashcard from our Coder Flashcards Library
 A definition from our Coder Definitions Page

KB101754

Member Field -

Also known as a Class Field.

A class variable defined with a specific class visibility, usually private visibility. A member property is different than a member field. A member property uses a member field to store values through accessor methods (getters and setters). For example, it is common to use a private member field to store the current value of a property. The current values of all the class member fields is the current state of the object.


Member Field vs Property Suggestion

If a class attribute is used outside the class, always make it either a read-write property or a read-only property. If a class attribute is only used within a class, make it a member field with the appropriate visibility (usually private).

Member Field Visibility Suggestion

Fields should generally be private. Access to fields by external classes should be indirect, usually by means of a property, sometimes by methods, or another means like an indexer. Sometimes it is necessary to make the visibility of a member field protected so descendant classes can use the member field. However, your first choice should be private visibility and you should avoid public member fields (see exception below).

Note: For demonstration purposes, we frequently use public member fields in our documentation, but this is generally not recommended in practice.

The exception is read-only member fields which are supported by some languages. Since read-only member fields are like constants, set when you initialize the member field and cannot be modified, it is acceptable to use public read-only member fields. Read-only member fields mean less code. Less code is cleaner and easier to maintain.

Member Fields, Class Variables, and Instance Variables

The term class variable is frequently interchangeable with member field. However, in some contexts, a class variable might refer to a static member field (no object instance required).

The term instance variable is also frequently interchangeable with member field. However, given a context where one is distinguishing between a static member field and a non-static member field, the term instance variable would refer to the non-static member field.

More Info

Code:  ASP Classic Member Field
Code:  C# Member Field
Code:  Delphi Member Field
Code:  Delphi Prism Member Field
Code:  Java Member Field
Code:  VB.Net Member Field

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1162A1
Enter key:
Definition Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101754 Counter
10319
Since 12/25/2008

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech