Textbook Notes (290,000)
CA (170,000)
Ryerson (10,000)
CPS (9)
Chapter 2

CPS 311 Chapter Notes - Chapter 2: Minimum Bounding Box, Adenosine A2B Receptor, Liskov Substitution Principle


Department
Computer Science
Course Code
CPS 311
Professor
Joshua D.Panar
Chapter
2

Page:
of 14
Smalltalk Midterm
Major elements of OOP design: hierarchy, abstraction, encapsulation, modularity
Abstraction: A simplified description or view of something that emphasizes characteristics or purposes
relevant to the user, while suppressing details that are immaterial or distracting. i.e.- hierarchical level
Capture major characteristics and ignore inessential details
Encapsulation is the process of combining data and functions into a single unit called class. In
Encapsulation, the data is not accessed directly; it is accessed through the functions present inside the
class. In simpler words, attributes of the class are kept private and public getter and setter methods are
provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.
Keeps data safe from external interference and misuse.
The combining together of attributes (data) and methods (behaviour/processes) into a single
abstract data type with a public interface and a private implementation. This allows the
implementation to be altered without affecting the interface
Canonical form: hierarchies all together; contains many objects each instantiated from a class
Modularity - is the degree to which a system's components may be separated and recombined
Decomposition couple and cohesion
Coupling: how one class is tied to another class, low coupling desirable
Cohesion: how parts of a class logically fit together as a unit, high cohesion desirable
Generally, high cohesion = loose coupling is good
Inheritance is from abstraction, hierarchy
Liskov sustitution priniple – a subclass object must be useable wherever a superclass object
could have been used
Smalltalk is dynamically typed (aka untyped)
Polymorphism: objects from different classes respond to a given message in their own way
Same signature in different classes
Dynamic binding supports polymorphism
A message invokes different methods in different classes
vs overloading is same message, different argument, with ONE class
Dynamic binding, receiver object (storage) is pointed to by pointer variable (name)
Message is sent to pointer variable
Three types of polymorphism: inheritance (two classes are in a direct inheritance), ad hoc (two
different classes have same method name defined), and parametric polymorphism (
Binding: WHEN names bound to storage/ function names become function code in memory/connecting a
method call to a method body
Static binding: compilation
Dynamic binding: runtime
Classes: groups objects with same abstraction
Instance variables: each object has its own values for most attributes
Class variable: value common for all instances
Class method: A method that provides behavior for a class. Message to invoke class methods are sent to
the class, rather than to instance of the class.
Cannot access instance variable since messages for classes are sent before there are any
instances
Instance method: A method that provides behavior for instances of class. Messages that invoke instance
methods are sent to particular instances, rather than to the class as a whole.
Dictionary: hashed storage; collection of methods, contains words and their definitions
Top level -> uppermost hierarchy
High level -> overview
Instance variables and a pointer to the class is allocated for an object in storage
Class variables and class instance variables are allocated for a class in storage
find more resources at oneclass.com
find more resources at oneclass.com
Basically, storage holds instance variables/class variables
When you instantiate an object, it makes space for it in storage
A variable holds an object by making a pointer reference to it
Smalltalk:
Pure ojet-oriented concept
ONLY message passing
Everything is an object (no primitives)
Main reason to learn SmallTalk:
Foundation concepts; basis for learning almost any object oriented language
Smalltalk system, bytecode image interpreted by a virtual machine
Entire development environment (classes, methods) contained in the image … startig poit
Image appears as window (World) with subwindows
Classes loaded into image from sources file at startup
As you work, changes logged in change log
The Image
World holds other idos
Transcript, browsers, workspaces
Results often appear on Transcript window
Executable code written and run in workspace windows
Classes and methods seen in browsers (Nautilus)
Instantiation is the relation between an object and its class, the new keyword
Inheritance is a relation between classes
Smalltalk Rules:
Everything is an object
Every object is an instance of a class
Every class has a superclass
Classes hold methods while instances of classes share methods
Instances hold instance variables
Everything happens by sending messages
Method lookup follows the inheritance chain
Every class is an instance of a metaclass
Classes hold the instance methods, instance variable NAMES
Metaclasses hold the class methods, class variable NAMES
The metaclass hierarchy parallels the class hierarchy
Every metaclass inherits from Class and Behavior
Every metaclass is an instance of Metaclass
The metaclass of Metaclass is an instance of Metaclass
Metaclass is a class hose istaes are lasses; a lasss lass. Just as a ordiar lass defies the
behavior of certain objects, a metaclass defines the behavior of certain classes and their instances.
Coets i  
Identifier names are in pseudo-hungarian notation (names are meaningful)
All Smalltalk statements either assignment or message sent
For assignment, pointer to existing object placed into variables storage location
Variables are untyped
Statements separated by period (.)
Sending a message to a receiver invokes a method of the same name
Message sent right to left
find more resources at oneclass.com
find more resources at oneclass.com
Receiver Message
Message set to reeier
Class: invokes class method
Object: invokes instance method
To find instantiating class for object or class, message to be used is class
To find parent class for a class, message is superclass
Object is an instance of a Class. Any method needed to instantiate the class
to an object is a Class method. For example: creating an instance of a class
(method "new") is a class method where as initializing the instance variable
(method "initialize" may be) is an instance method.
Probably the main purpose of class methods is creating instances of objects, but
there are other uses of class methods namely answering general questions about
the class, for example the Date class would be able to answer the name of the
'n'th month.
Instance methods on the other hand are dependant on the value of an object's
state, such as what is the month of this date, or alter tha state of the instance,
such as addMonths: 2.
With multiple messages of equal precedence
Leftmost is sent first, generates an object
Next message sent to result of object of first message
If essage ot i lass or etalass of reeier, Message ot uderstood
Precedence : unary, binary, keyword
Unary message has no arguments
Binary messages
For arithmetic operations, relational operations
Takes one argument but would look silly with : i.e. +: would look silly
Keyword messages have arguments, one argument per keyword (follows : )
Fred at: 2 put: 27. Message is at:put: method has same name
Modifier methods sets value in the instance variables
Accessor methods returns value of instance variables
find more resources at oneclass.com
find more resources at oneclass.com