Lecture 5 - Definining a class, attributes and methods Flashcards
What is a class ?
A collection of similar
objects.
A class is a template or blueprint of objects of the same kind
Instances of a class are objects
What is object oriented Programming?
is a programming paradigm that uses abstraction (in the form of classes and objects) to create models based on the real world environment.
What does a object oriented program consist of ?
many well encapsulated objects and interacting with each other by sending messages
Object oriented features ?
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
Procedural-oriented programs:
focus on procedures, with function as basic unit.
Are not suitable of high-level abstraction for solving real life problems.
Object-oriented programs:
focus on components that the user perceives, with objects as basic unit.
Permit higher level of abstraction for solving real-life problems.
Ease in software design, in software maintenance and reusable software.
What does a class consist of ?
Attributes: (or fields) define the object’s state
Methods: define what can be done to them, i.e., object’s
behaviors
Constructors: create an object
Naming conventions for classes:
mixed case, each word starting upper case
E.g., BouncingBall, HelloWorld, ParetoArchive
Naming conventions for Methods and Attributes:
mixed case, lower case first letter
E.g., width, originX, borrowDate
E.g., brake, addValueToArchive, resetButton
What type of attributes are there ?
Instance attributes: belongs to objects.
Static attributes: belongs to the class. refers the common property of all objects (that is not unique
for each object) e.g. company name of employees. Through static keywords.
static final int NUMBER OF SIDES = 4;
What are methods ?
Methods are well-defined sets of instructions to perform a specific
task.
In a method you have :
Input data: known as method parameters or arguments
Output data: through return statement.
if the return type is void, no need to return.
What can a method access?
all of that class’s attributes (static and instance)
local variables
the parameters passed to it
variables declared within the method itself
What is method overloading :
two/more methods
share the same name, but with different method arguments.
What can methods be divided into:
Instance methods: belongs to objects.
Static methods: belongs to the class: The main() method is a static method. Through static keywords.