Reviewoo
Reviewoo
Reviewoo
Paradigms
CSI2120
Jochen Lang
EECS, University of Ottawa
Canada
Review of Object-oriented
Programming
• Acknowledgement
– These slides are a barely modified version of the slides for
Chapter 2, Object-Oriented Software Engineering:
Practical Software Development using UML and Java by
Tim Lethbridge and Robert Laganière
• Procedural paradigm:
– Software is organized around the notion of procedures
– Procedural abstraction
• Works as long as the data is simple
– Adding data abstractions
• Groups together the pieces of data that describe some
entity
• Helps reduce the system’s complexity.
– Such as records and structures
• Object
– A chunk of structured data in a running software system
– Has properties
• Representing its state
– Has behaviour
• How it acts and reacts
• May simulate the behaviour of an object in the real world
• A class:
– A unit of abstraction in an object oriented (OO) program
• A variable
– Refers to an object
– May refer to different objects at different points in time
• An object can be referred to by several different variables at
the same time
• Type of a variable
– Determines what classes of objects it may contain
• Inheritance
– The implicit possession by all subclasses of features defined
in its superclasses
See in Umple
• Abstraction
– Object -> something in the world
– Class -> objects
– Superclass -> subclasses
– Operation -> methods
– Attributes and associations -> instance variables
• Modularity
– Code can be constructed entirely of classes
• Encapsulation
– Details can be hidden in classes
– This gives rise to information hiding:
• Programmers do not need to know all the details of a class
• Origin
– The first object oriented programming language was Simula-67
• designed to allow programmers to write simulation
programs
• 1980s
– Smalltalk was developed at Xerox PARC
• New syntax, large open-source library of reusable code,
bytecode, platform independence, garbage collection.
– C++ was developed by B. Stroustrup at ATT Labs
• Started in 1979. The initial version was called "C with
Classes".
• 1990s
– Sun Microsystems started a project to design a language that
could be used in consumer ‘smart devices’: Oak
• When the Internet gained popularity, Sun seized the
opportunity and renamed the new language Java. It was
first presented at the SunWorld ’95 conference.
• Thread:
– Sequence of executing statements that can be running
concurrently with other threads
• To create a thread in Java:
1. Create a class implementing Runnable or create a class
extending Thread
2. Implement the run method as a loop that does something
for a period of time
3. Create an instance of this class
4. Invoke the start operation, which calls run
• Comment extensively
– Comment whatever is non-obvious
– Do not comment the obvious
– Comments should be 25-50% of the code
– Stroustrup: “If the comment and code disagree, both are
probably wrong”.
• Organize class elements consistently
– Variables, constructors, public methods then private
methods
• Be consistent regarding layout of code
– Stroustrup: “Such style issues are a matter of personal taste.
Often, opinions about code layout are strongly held, but
probably consistency matters more than any particular style”