Object Oriented Paradigm an object is an instantiation from a class, e.g., you have a pet cat, who's name is Garfield, then Garfield is a object (of the class cat) to invoke an method, simply do obj.method( ) or obj->method( ), the Ming- Hwa Wang, Ph.D. former is object reference syntax, and the latter is pointer syntax Department of Computer Engineering Santa Clara University Relationships a-kind-of relationship: a subclass inherits and adds more attributes Object Oriented Paradigm/Programming (OOP) and/or methods from its super class to become somewhat "specialized" similar to Lego, which kids build new toys from assembling the existing is-a relationship: an object of a subclass is an object of its super class construction blocks of different shapes part-of relationship: OOP - doing programs by reusing (composing/inheriting) objects has-a relationship: (instantiated from classes) as much as possible, and only writing code

when no exiting objects can be applied inheritance Two Fundamental Principles for OOP a sub/child/derived/extended class can inherit all properties from its generalization or reusability: the classes designed should target to super/parent/base/original class, with or without reusability, i.e., it should very generic and can be applied to lots of modification/override or addition situations/applications without much efforts; reusability comes from single inheritance and multiple inheritance (watch out naming inheritance and/or composition conflicts) encapsulation or information hiding: we can hide detailed or composition implementation specific information away from the users/programmers, so changing implementation using the same interfaces will not need Abstract or Virtual Classes modifying the application code only used as a super class for other classes, only specified but not fully defined, and can't be instantiated OOP Language vs. Environment its derived classes must redefine all the virtual properties a language provides syntax/semantics (by its compiler), e.g., Modular, C++, etc., programmers have to write code for everything to make Generic Types: Template programs work if a class is parameterized with another type, once an object of that class an environment provide a language and its library, e.g., , Java, is created, the parameterized type is replaced by an actual data type etc., programmers do not have to write a lot of code to do programming, instead, they just try to reuse the existing code as much as they can Static and Dynamic Bindings static (before compile time) binding Classes vs. Objects dynamic (after compile time, i.e., at runtime) binding a class is a kind or a type, e.g., cat and dog are classes; a class is a data structure, it contains Polymorphism data/attributes/variables to store the states of the class the ability to request that the same operations be performed by different methods/messages/operators/functions/procedures/behaviors to objects, or many objects to perform the same action manipulate its data (an implementation), and to provide the concept of dynamic binding allows a variable to take different types interfaces/API to the users dependent on the content at a particular time manager functions manage class objects and handling activities (initialization, assignment, memory management, type conversion), Function Overloading usually invoked implicitly by the compiler, e.g., constructor depending on function name and its parameters (number of parameters implementor functions: provide the capabilities associated with the and their types, but not return type though) class abstraction helping functions: provide support for the other class member constructors and destructors functions, generally declared as private default constructor or user defined constructors access functions: support user access to otherwise private data copy constructor level of accessibility: private, protected, public assignment constructor

The Design of OOP creational: How an object can be created. This often involves the way you analyze a problem (break it down) will give you a particular set isolating the details of object creation so your code isn't dependent of objects, and there are 3 helpful ways to identify objects when you are on what types of objects there are and thus doesn't have to be designing a system: changed when you add a new type of object. a checklist of kinds of objects (Pressman): external entities, things, structural: These affect the way objects are connected with other occurrences or events, roles, organizational units, places, structures objects to ensure that changes in the system don't require changes in the grammatical parse you select the nouns and noun phrases as the to those connections. Structural are often dictated by potential objects and verbs as possible operations performed on or by project constraints. the objects behavioral: Objects that handle particular types of actions within a 6 characteristics to filter a list of potential objects. (Coad Yourdon) program. These encapsulate processes that you want to perform, retained information - the object needs to remember information such as interpreting a language, fulfilling a request, moving through needed service - the object has operations which change its a sequence (as in an ), or implementing an . attributes concurrency: common attributes - all occurrences of an object have the attributes basic ways to keep code simple and straightforward common operations - all occurrences of an object have the messenger: packages information into an object which is passed operations around, instead of passing all the pieces around separately essential requirements - external entities which produce consume collecting parameter: captures information from the function to information which it is passed (using container to dynamically add objects) multiple attributes - single attributes might be thought of as being an attribute of a larger object, not an object in their own right Name Description

Class Diagrams Creational patterns UML (Unified Modeling Language) notation example Provide an interface for creating families of related or Person class name Abstract factory dependent objects without specifying their concrete firstName: String classes. lastName: String attributes Define an interface for creating an object, but let age: Integer Factory method subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. setFirstName( ) getFirstName( ) Separate the construction of a complex object from its setLastName( ) operation Builder representation so that the same construction process getLastName( ) can create different representations. setAge( ) Tactic of delaying the creation of an object, the getAge( ) calculation of a value, or some other expensive process until the first time it is needed. graphical notation Avoid expensive acquisition and release of resources by Object pool Design recycling objects that are no longer in use the pattern concept: encapsulate change. The basic concept of a pattern Specify the kinds of objects to create using a can also be seen as the basic concept of program design in general: Prototype prototypical instance, and create new objects by adding layers of abstraction. Whenever you abstract something, you're copying this prototype. isolating particular details, and one of the most compelling motivations for this is to separate things that change from things that stay the same. Ensure a class only has one instance, and provide a two fundamental are implemented in object-oriented Singleton global point of access to it (using static member and language compilers: inheritance and composition. Other minor ones are making all constructors/destructors private). constructors/destructors (as guaranteed initialization and cleanup design A class with a private constructor that contains only Utility pattern), and aggregation (which is erroneously classified as a pattern.) static methods. Gang of Four (Gamma, Helm, Johnson & Vlissides) discusses 23 patterns, classified under 4 purposes: Structural patterns

Convert the interface of a class into another interface Observer Define a one-to-many dependency between objects so Adapter clients expect. Adapter lets classes work together that that when one object changes state, all its dependents couldn't otherwise because of incompatible interfaces. are notified and updated automatically. Decouple an abstraction from its implementation so Allow an object to alter its behavior when its internal Bridge that the two can vary independently. State state changes. The object will appear to change its class. Compose objects into tree structures to represent part- whole hierarchies. Composite lets clients treat Define a family of , encapsulate each one, Composite individual objects and compositions of objects Strategy and make them interchangeable. Strategy lets the uniformly. algorithm vary independently from clients that use it. Attach additional responsibilities to an object Specification Recombinable business logic in a boolean fashion Decorator dynamically. Decorators provide a flexible alternative to Define the skeleton of an algorithm in an operation, subclassing for extending functionality. deferring some steps to subclasses. Template Method Template method Provide a unified interface to a set of interfaces in a lets subclasses redefine certain steps of an algorithm Facade subsystem. Facade defines a higher-level interface that without changing the algorithm's structure. makes the subsystem easier to use. Represent an operation to be performed on the Use sharing to support large numbers of fine-grained elements of an object structure. Visitor lets you define Flyweight Visitor objects efficiently. a new operation without changing the classes of the elements on which it operates. Provide a surrogate or placeholder for another object to Proxy control access to it. Single-serving Optimize the implementation of a visitor that is visitor allocated, used only once, and then deleted Behavioral patterns Hierarchical Provide a way to visit every node in a hierarchical data Avoid coupling the sender of a request to its receiver visitor structure such as a tree. Chain of by giving more than one object a chance to handle the responsibility request. Chain the receiving objects and pass the Concurrency patterns request along the chain until an object handles it. The decouples method Encapsulate a request as an object, thereby letting you execution from method invocation that reside in their parameterize clients with different requests, queue or Active Object own of control. The goal is to introduce Command log requests, and support undoable operations. An concurrency, by using asynchronous method invocation object-oriented replacement for callbacks (also and a scheduler for handling requests. decoupling event handling). The Balking pattern is a pattern that Given a language, define a representation for its Balking only executes an action on an object when the object is Interpreter grammar along with an interpreter that uses the in a particular state. representation to interpret sentences in the language. Double-checked locking is a Provide a way to access the elements of an aggregate also known as "double-checked locking optimization". Iterator object sequentially without exposing its underlying The pattern is designed to reduce the overhead of representation. acquiring a by first testing the locking criterion Double checked (the 'lock hint') in an unsafe manner; only if that Define an object that encapsulates how a set of objects locking succeeds does the actual lock proceed. interact. Mediator promotes by keeping Mediator The pattern, when implemented in some objects from referring to each other explicitly, and it language/hardware combinations, can be unsafe. It can lets you vary their interaction independently. therefore sometimes be considered to be an anti- Without violating encapsulation, capture and pattern. Memento externalize an object's internal state so that the object In concurrent programming, is a can be restored to this state later. Guarded software design pattern for managing operations that

require both a lock to be acquired and a precondition to be satisfied before the operation can be executed. Leaders/followers A monitor is an approach to synchronize two or more Monitor object computer tasks that use a shared resource, usually a hardware device or a set of variables. A read/write lock pattern or simply RWL is a software design pattern that allows concurrent read access to an Read write lock object but requires exclusive access for write operations. The scheduler pattern is a software design pattern. It is a used to explicitly control when Scheduler threads may execute single-threaded code. In the pattern in programming, a number of threads are created to perform a number of tasks, Thread pool which are usually organized in a queue. Typically, there are many more tasks than threads. Thread-local storage (TLS) is a Thread-specific method that uses static or global memory local to a storage thread. The reactor design pattern is a concurrent programming pattern for handling service requests delivered concurrently to a service handler by one or Reactor more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers. This document was created with Win2PDF available at http://www.win2pdf.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only. This page will not be added after purchasing Win2PDF.