If we wish to record information about a student, what data might we require? Some examples might be
The student's name
The student's birthdate
His or her address
The student's designated major field of study, if the student has declared one yet
His or her cumulative grade point average (GPA)
Who the student's faculty advisor is
A list of the courses that the student is currently enrolled in this semester (i.e., the student's current course load)
A history of all of the courses that the student has taken to date, the semester/year in which each was taken, and the grade that was earned for each: in other words, the student's transcript
and so on. Now, how about for an academic course? Perhaps we'd wish to record
The course number (e.g., "ART 101")
The course name (e.g., "Introductory Basketweaving")
A list of all of the courses that must have been successfully completed by a student prior to allowing that student to register for this course (i.e., the course's prerequisites)
The number of credit hours that the course is worth
A list of the professors who have been approved to teach this course
and so on. In object nomenclature, the data elements used to describe an object are referred to as the object's attributes.
Important?/td> |
Use of the term "attribute" in this fashion is a language-neutral object modeling and programming convention. But, all .NET languages (including C#) have a specific programming construct called an attribute, which has a more complex purpose than simply referring to a data element of an object. It's important not to confuse the two uses of the term "attribute" when talking specifically about one of the .NET languages. (.NET languages instead prefer to use the term "field" to refer to an object's data elements/attributes in the generic sense of the word.) We'll explain what an attribute in the C# (.NET) specific sense is all about in Chapter 13. For the time being, however (i.e., throughout the remainder of Parts One and Two of the book), whenever we use the term "attribute," we're using it in the generic OO sense. |
An object's attribute values, when taken collectively, are said to define the state, or condition, of the object. For example, if we wanted to determine whether or not a student is "eligible to graduate" (a state), we might look at a combination of
The student's transcript (an attribute), and
The list of courses he or she is currently enrolled in (a second attribute)
to see if the student is indeed expected to have satisfied the course requirements for their chosen major field of study (a third attribute) by the end of the current academic year.
A given attribute may be simple—for example, "GPA", which can be represented as a simple floating point number—or complex—for example, "transcript", which represents a rather extensive collection of information with no simple representation (at least as far as C# simple types are concerned).