Object Oriented Programming FILS 2014-2015 Andrei Vasilateanu, PhD
Object Oriented Programming FILS 2014-2015
Andrei Vasilateanu, PhD
Administration
Course Master:
• Andrei Vasilateanu, andraevs@gmail.com
Teaching Assistants: • Radu Ioanitescu, ioanitescuradu@yahoo.com
Grading: • Final exam 40%
• Laboratory 60% • 2 Tests 30%
• Attendance 10%
• Homework + Activity 20%
Course Policies:
• Individual HW, >50% in exam, no late HW
mailto:andraevs@gmail.com
Bibliography
The lectures are not enough, extra reading is necessary
Romanian:
• L.D.Serbanati, C.Bogdan, Programare orientata spre obiecte cu exemplificari in limbajul Java, vol 2
English:
• C. Horstmann, G. Cornell, “Core Java 2”
• K.Mughal, R. Rasmussen, “Programmer's Guide to Java SCJP Certification”
• http://docs.oracle.com/javase/tutorial/
• J. Bloch, C. Persuati, “Effective Java”
• S. McConnell, “Code Complete”
http://docs.oracle.com/javase/tutorial/
Overview of the course
Revision of basic OOP concepts from PL
Interfaces
Nested classes
Generics
Collections
Graphical User Interfaces (AWT + Swing)
Exception Handling
Concurrency
Reflexion
Revision Object Oriented Programming
Programming paradigm
• Data + functions
• Code reuse
• Object Oriented Analysis and Design
O1
O4 O3
O2 m1
m3
m2
Concepts
A concept is an idea or notion that we apply to entities in the real world or our imagination
1. For us, concepts are a recognition device. The concepts may be: Tangible (person, car, table), Intangible (time, quality, company), Roles
(doctor, patient, owner), Judgments (high pay, good example, productive job), Relational (marriage, partnership, ownership), Events (sale, purchase, market crash), Other types of concepts (string, number, icon, image, signal, process)
2. For us concepts are also a test for reality: we can apply concepts to entities in our reality and discard concepts that no longer apply. Each concept is based on tests that determine when it applies.
Person Employee
Company
Headquarter
Car
Model
Patient
Efficient Organization
Contract
can be a can be a
owns employs
characterizes
has
is an instance of
subject
owns
subscribes
Town
lives in
registered
registered at
Marriage
Concept We use concepts as units of knowledge in which each has an intension and
an extension. There two sides of the same coin. • Intension (definition, understanding): the complete definition of the concept and
the test that determines whether or not the concept applies to an entity. • Extension: the set of all entities to which the concept applies.
A domain is a collection of entities in a selected area of interest. A domain specification is the collection of concepts that apply to a domain. An instance of a concept is an entity in the real world or our imagination to
which a concept applies.
{ Extension }
{ Intension }
A shared notion or idea that applies to certain objects in our awareness.
Type (i.e. Concept)
Person
Employee
Event Type
Company
Order Item
Order
{ Symbolizes }
Manager
Objects Objects in OOP programming are computer-oriented representations of
concept instances. Each object in our programs should abstract a concept instance in the real
world or our imagination. Three key characteristics of objects derived from characteristics of the real
entities: • The object's behaviour - what can you do with this object, or what methods can
you apply to it? The behaviour of an object is defined by the methods that you can call. The state of an object can influence its behaviour .
• The object's state - how does the object react when you apply those methods? the object's state is all stored information about what it currently looks like. A change in the state of an object must be a consequence of method calls.
• The object's identity - how is the object distinguished from others that may have the same behaviour and state? The state of an object does not completely describe it, since each object has a distinct identity.
A class of objects is the description of a set of similar objects with the same state components and behaviour.
Classification is the act or result of applying a concept (i.e. type) to one of its instances. Further we can define classification in the OOP programming:
Class Object
classifier
instance
1..*
*
Classification Relationship
Relationships Between Classes
The most common relationships between classes are: • Dependence ("uses–a"): a class depends on another class if its methods
manipulate objects of that class. • Association ("knows–a"): A user-defined relationship. • Aggregation ("has–a"): the act or result of forming an object whole
using other objects as its parts • Generalization ("is–a"): the act or result of distinguishing a concept (i.e.
type) that completely includes or encompasses another.
Order
RushOrder
Item Account check for credit
*
OrderManager
*
Generalization Generalization is the act or result of distinguishing a concept (i.e. type) that
completely includes or encompasses another. Generalization enables us to say that all instances of a specific type are also
instances of more general type – but not necessarily the other way around. With generalization we can define hierarchies of types, forming more and
more general types. The more general type is called supertype. The opposite of generalization is specialization. The specialized types are subtypes.
Generalization in Java is expressed as class extension. In general, if class A extends class B, class A inherits variables and methods
from class B, but has more capabilities.
Inheritance
Code reuse in OO = create new classes that are built upon existing classes.
Polymorphism = An object variable (such as the variable e) can
refer to multiple actual types.
Constructor inheritance
Method overriding • Covariant return (only reference types)
• Accesibility
• @Override
• Exception throwing
Method and field hiding
Cohesion and Coupling
Cohesion = inter-class measure of how well-structured and closely-related the functionality is in a class. => well-defined and related tasks
Coupling = measure of intra-class dependencies.
High cohesion and loose coupling => maintanability, reusability, extensibility and reliability