Introduction to classes objects methods and attributes
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

Introduction to Classes, Objects, Methods and Attributes PowerPoint PPT Presentation


  • 30 Views
  • Uploaded on
  • Presentation posted in: General

Introduction to Classes, Objects, Methods and Attributes. Lecture # 5. Object-Oriented Programming. Object-oriented programming is centered on creating objects rather than procedures. Objects are a melding of data and procedures that manipulate that data.

Download Presentation

Introduction to Classes, Objects, Methods and Attributes

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to classes objects methods and attributes

Introduction to Classes, Objects, Methods and Attributes

Lecture # 5


Object oriented programming

Object-Oriented Programming

Object-oriented programming is centered on creating objects rather than procedures.

Objects are a melding of data and procedures that manipulate that data.

Data in an object are known as attributes.

Procedures in an object are known as methods.


Object oriented programming data hiding

Object-Oriented ProgrammingData Hiding

Data hiding is important for several reasons.

It protects attributes from accidental corruption by outside objects.

It hides the details of how an object works, so the programmer can concentrate on using it.

It allows the maintainer of the object to have the ability to modify the internal functioning of the object without “breaking” someone else’s code.


Object oriented programming code reusability

Object-Oriented ProgrammingCode Reusability

Object-Oriented Programming (OOP) has encouraged component reusability.

A component is a software object contains data and methods that represents a specific concept or service.

Components typically are not stand-alone programs.

Components can be used by programs that need the component’s service.

Reuse of code promotes the rapid development of larger software projects.


Encapsulation

Encapsulation

Classes should be as limited in scope as needed to accomplish the goal.

Each class should contain all that is needed for it to operate.

Enclosing the proper attributes and methods inside a single class is called encapsulation.

Encapsulation ensures that the class is self-contained.


Classes and objects

Classes and Objects

Components are objects.

The programmer determines the attributes and methods needed, and then creates a class.

A class is a collection of programming statements that define the required object

A class as a “blueprint” that objects may be created from.

An object is the realization (instantiation) of a class in memory.


Object oriented programming1

Object-Oriented Programming

Object

Attributes (data)

Methods(behaviors / procedures)


Classes and objects1

Classes and Objects

Classes can be used to instantiate as many objects as are needed.

Each object that is created from a class is called an instance of the class.

A program is simply a collection of objects that interact with each other to accomplish a goal.


Classes and objects2

Classes and Objects

housefly object

The Insect class defines the attributes

and methods that will exist in all objects

that are an instances of the Insect class.

The housefly object is an

instance of the Insect class.

Insect class

The mosquito object is an

instance of the Insect class.

mosquito object


Designing a class

Designing a Class

When designing a class, decisions about the following must be made.

what data must be accounted for,

what actions need to be performed,

what data can be modified,

what data needs to be accessible, and

any rules as to how data should be modified.

Class design typically is done with the aid of a Unified Modeling Language (UML) diagram.


Uml class diagram

UML Class Diagram

A UML class diagram is a graphical tool that can aid in the design of a class.

The diagram has three main sections.

Class Name

Attributes

Methods

UML diagrams are easily converted

to Java class files. There will be more

about UML diagrams a little later.

  • The class name should concisely reflect whatthe class represents.


Attributes

Attributes

The data elements of a class define the object to be instantiated from the class.

The attributes must be specific to the class and define it completely.

Example: A rectangle is defined by

length

width.

The attributes are then accessed by methods within the class.


Methods

Methods

The class’ methods define the actions that an instance of the class can perform

Methods headers have a format:

AccessModifierReturnTypeMethodName(Parameters)

{

//Method body.

}

Methods that need to be used by other classes should be made public.


Methods1

Methods

The attributes of a class might need to be:

changed,

accessed, and

calculated.

The methods that change and access attributes are called accessors and mutators.


  • Login