Escolar Documentos
Profissional Documentos
Cultura Documentos
Java is Object Oriented (OO): dividing programs into modules (objects) helps manage software complexity. Java is robust: errors in Java don't usually cause system crashes as in other languages. Java is platform independent: programs run without changes on all different platforms. Java is a distributed language: programs can easily be run on computer networks. Java is a secure language: it guards against viruses and other untrusted code.
Universiti Malaysia Sabah 3
Labuan International Campus Labuan School of Informatics Science
An Object-oriented program (OOP) is a set of interacting objects that models a collection of real world objects.
Me MyVi IT00203 Students
DELL Laptop
Whereas this model and a computer program is dynamic: its objects communicate with each other and change over time.
Universiti Malaysia Sabah 4
Labuan International Campus Labuan School of Informatics Science
Now, its your turn to think of some scenarios with a few objects..
An object is any thing whatsoever. It can be physical (Car, Money); mental (Idea); natural (Animal, Flower); artificial (ATM).
An objects label consists of its id and its type In UML objects are represented by rectangles Labeled with a two part label of the form id:Type.
christy : Account
Universiti Malaysia Sabah 7
Labuan International Campus Labuan School of Informatics Science
Objects have certain characteristic attributes which have certain values. An objects collection of attributes and values is sometimes called its state. Student
In UML, an objects attributes are represented in the second partition of the rectangle.
student1:Student
name= Christian John course = Multimedia CGPA = 3.00
student2:Student
name= Emily Victor course = E-Commerce
CGPA = 3.57
Objects have characteristic actions or behaviors. ACTIONS associated with an object can be used to send messages--changeCourse(ECommerce)--to the object. Arguments (E-Commerce) is data value that can be passed as part of the message.
changeCourse(E-Commerce)
A message is represented as an arrow.
Universiti Malaysia Sabah 11
Labuan International Campus Labuan School of Informatics Science
student1:Student
name= Christian John course = Multimedia CGPA = 3.00
A customer is trying to check his account balance through an ATM machine in the hotel lobby.
A class (Rectangle) is a blueprint or template of all objects of a certain type. It encapsulates the attributes and actions that characterize a certain type of object. Like a cookie cutter for a cookie, it gives a general type of rectangle. An object is an instance of a class.
A variable == an attribute, is a named memory location that can store a certain type of value. A method == an action, is a named chunk of code that can be invoked to perform a certain predefined set of actions.
Variables Methods
Universiti Malaysia Sabah 14
Labuan International Campus Labuan School of Informatics Science
A instance variable (or instance method) is a variable or method that belongs to an object. A class variable (or class method) is a variable or method that is associated with the class itself.
Class variable
Instance variables
rect2
rect1
The Rectangle class and two of its instances. Note that class variables are underlined in UML.
Universiti Malaysia Sabah
Labuan International Campus Labuan School of Informatics Science
15
A constructor is a special method, associated with the class, that is used to create instances of that class. Example: We call the Rectangle() constructor to create an instance with length=25, width=10 and located at x=100 and y=50.
to each other?
most general to most specific. A subclass is more specific than its superclass.
Classes Superclass
Subclasses
A subclass inherits elements (variables and methods) from its superclasses. Inherited elements can be specialized in the subclass.
What is an object-oriented program composed of? Many objects that communicating with each other. What are the important principles in designing an OO program?
Divide-and-Conquer Principle
Problem Solving: Break problems (programs) into
Encapsulation Principle
Each object knows how to solve its task and has
the information it needs. Example: A dentist encapsulates the expertise needed to diagnose and treat a toothache. Sales agent is the sales expert. The shipping clerk is the shipping expert.
Interface Principle
Each object has a well-defined interface, so you
know how to interact with it. Example: Digital vs. analog clock interfaces.
cooperatively, objects hide details of their expertise. Example: Customer neednt know how the sales agent records the order. To use the analog watch, we neednt know how its time-keeping mechanism works.
Generality Principle
Objects are designed to solve a kind of task rather
than a singular task. Java comes with an extensive library of classes that specialize in performing certain kinds of input and output operations. Example: Sales agents sell all kinds of stuff.
Extensibility Principle
An objects expertise can be extended or
specialized. Example: One sales agent specializes in software sales and another in hardware sales.
A(n) ________ in a Java program encapsulates programs ________ and __________. A ________ is a template of an object. A _______ is a special method used to construct objects. Objects interact with each other by sending __________ back and forth.
Universiti Malaysia Sabah
Labuan International Campus Labuan School of Informatics Science 28
A(n) __________ is a location in memory where a value is stored. Class inheritance means that subclass inherits characteristics and behaviors from their __________.
__________ diagrams are used to illustrate object-oriented design. Dividing a problem or a task into parts is an example of the ___________ principle. Designing a class so that it shields certain parts of an object from other objects is an example of the _________ principle.
Universiti Malaysia Sabah
Labuan International Campus Labuan School of Informatics Science 30