Lecture3 Flashcards
What is the OOP approach?
With this approach, a computer system is viewed as a collection of
interacting objects. Objects are viewed as things (similar to
objects in the real world)
These objects have certain features (or attributes) and they
exhibit certain behavior. Similar things can be grouped together
and classified as a certain type of thing. E.g. all the cars on the
road are classified as one type of thing – a car. These types can be
further classified into sub-types (e.g. sedans, trucks etc.)
The type is called a class and the specific instance of it an object.
Things can interact and you can interact with things. – objects in a
computer system can interact with people and the other way
around. People do not need to know much about these objects to
interact with it.
Concepts: object relationships, class, objects, methods, reuse,
information hiding, inheritance, polymorphism
Interface classes
Without knowing it we have already
worked with many classes and objects
* All of the following are classes:
– Console
– Form
– TextBox
– Button
* These classes are interface classes that are
used to help users interact with programs
Entity Classes
We can also create our own entity classes
* These classes are used to handle the
information on real world entities such as:
– Clients
– Invoices
– Departments
– Countries
– Prices
What does every class have?
Data attributes called data members
– Optionally properties
– Optionally methods (that uses or processes the
data attributes)
– Optionally events (mostly with interface classes,
seldom with entity classe
How to declare an object
Random myGenerator = new Random();
* With this statement we declare a reference – we notify the compiler
that a object named myGenerator will exist
Random myGenerator = new Random();
* With this part of the statement memory is actually set aside for the
object – loosely referred to as the instantiation of the object.
Declaration of an object can thus be done in two parts as well:
Random myGenerator;
myGenerator = new Random();
What does every class consist of?
Inside the brackets of the Student class we define our
class
Every class consists of a number of parts:
– Data attributes or data members
– Optional constructor method
– Optional other methods
– Optional properties
– Optional events (not handled in this course)
We will discuss each on a separate slide
What is a constructor and default constructor
A constructor is a special type of instance
method:
* It does not return a value
* void is not included
* Same identifier as the class name
* Overloaded (a class can have more than
one, each with a different number of
parameters)
* Default constructor has no parameters
What is the code for the two types of constructors?
The public access modifier is always associated with
constructors
//Default constructor
public Student ( )
{
}
//Constructor with one parameter
public Student (int studentID )
{
studentNumber = studentID;