CSE3302 - FinalReview2.0

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

algorithm copies recursively visited nodes into one long to space queue, without fragmentation

Cheney's Algorithm

Like a function prototype, a class is a static declaration that defines all of the types in its subclass instantiations, which actually occupy memory and execute at runtime. Thus, a class is a kind of a "type."

Class

Behave like predefined types in how they access data Ex: a programmer defined type represented by an opaque integer stack data structure cannot be transparently accessed, as if it were an array Consist of: The new types (class) name The new types implementation Names of the new types operations and the types of their parameters and returned values Those operations implementations A security capsule which separates all operations user interfaces from implementations May encapsulate other ADT's Denying User access to ADT implementations: Prevents users from violating the ADT creators type Keeps innovative algorithms secret competitors Enables implementation improvements without breaking legacy code interfaces Improves the software development process by decoupling implementation from applications Three kinds of operations: Constructor - specifies new data items of type ADT in terms of other known types Transformer - (operator) computes values of type ADT from the values of other known types Observer - (operator) computes a value of a known type from values of type ADT Four important concepts: Interface - visible parts of and ADT, which include signature and its operations specifications Implementation - The ADT's and its operations concrete type representations Encapsulation - Wrapping a more concrete type in a more abstract type Data Hiding - Denying user access to ADT implementations

Abstract Data Type

With considerable effort, ADTs can be made to perform almost as well as O-O classes To add an operation to the Counter ADT Add an all new NewCounter1 ADT with overloaded argument types--context tells the computer which to call. Maintaining the ADT together is a problem Or embed Counter in a NewCounter2 ADT. But that requires relaxing ADTs to allow compatibility of the Counter and NewCounter2's types, which ruins their encapsulation Both alternatives lead to many serious problems

Abstract Data Type

Locally Type safe Originally the US DoD declared Ada is the only O-O acceptable mission critical programming language in the 80s, and recently replaced it with C++

Ada

In the general sense of first order logic a clause is this formula: All variables X1,...Xm that occur in the literals (L1 or L2 or ... or Ln) The literals are atoms or negated atoms Separating the negated atoms from the others gives: All variables X1,...,Xm that occur in the literals (A1 or A2 or ... or Anor -B1 or -B2 or ... or -Bn) A logical equivalence allows us to replace disjunction with implication A1,...,Am ← B1,...,Bk Referred to in the next three bullets A (definite) program clause has only one un-negated atom (m=1) A fact is a definite clause containing no negaated atoms (k=0) A query or goal is a "negative clause" in which m=0

Clauses

The hidden code that constructs, transforms and observes to create and ADT, in terms of predefined types and component ADT's

Client

In designing the base class T below, a software engineer tries to provide for all needed functionality. But a programmer often adds a derived subclass S, which inherits the base class T and adds an instance variable or a method of its own: Synonym in C++ for "superclass" in Java.

Base class

All parts work together toward a common purpose

Cohesive

Type Unsafe US DoD's only acceptable mission-critical programming language currently

C++

Derived C++ classes (subclasses) introduce the inheritance relation. And they introduce the subtype relation, when derived classes declare their base classes (superclasses) public. If not public, the subtype relation disappears. Instead of Java's interface subtypes, C++ offers pure virtual abstract base classes without implementations. These are subtypes without inheritance.

C++ Inheritance

Memory made inaccessible by the corruption of its pointer

Dereference

derived subclass S, which inherits the base class T and adds an instance variable or a method of its own

Derived class

A constructor runs automatically, when an instance is created. The superclass' constructor runs then too; i.e., constructor chaining. A constructor typically does a once-and-for-all initialization. It has the same name as its class. The compiler can choose among multiple constructors in a class, by matching their return types and argument types with static context. There also is a destructor that typically frees any memory that the class may have allocated in the stack or heap. (It bears the constructor's name, preceded by a not sign.)

Constructor

When a memory allocation is delayed for lack of memory, the stop&copy collector recursively copies only live objects from the heaps from space into its equally sized compacted to space, modifying all pointers on the fly The from and to spaces the swap and repeat Precautions are taken to prevent copying an object of multiple pointers many times Runtime is proportional to the number of live objects; dead ones don't move. Increasing memory size decreases runtime by reducing garbage collector calling frequency

Copy Collector

Neither the ADT client nor the ADT's implementer violates the ADT's signature or its operations specifications

Correct

Couldn't find

Correctness

Creates an instance of the Counter class in the heap

Counter c = new Counter()

Change the value of the counter class private count

Counter.set(x) = 1

Instances of a class that actually occupy memory and execute at runtime.

Instantiations

A static type declaration of a record-like structure of instance variables and methods that operate on them.

Interface

The "diamond problem" of a subclass double-inheriting from superclasses, both of which unknowingly inherit from a single supersuperclass, actually arises frequently. Following solves the diamond problem: Raise an exception. Require the A::f() or B::f() notation in calls. Follow a convention of, for example, choosing the first class named in the subclass' extension clause. Override the superclass' definition of f() in subclasses.

Diamond Problem

prevents error

Dynamic Downcast

The circa 1980 languages Self, Dylan, and Javascript had no classes A new object would clone a "prototype" object, subsequently referred to as its parent It delegated cals to its parent's method if it had no implementation of that method itslef Modern O-O languages use this delegation mechanism to make inheritance flexible and powerful. Objects can dnamically change behaviiors by changing references to parents at runtime

Delagation Languages

Couldn't find

Dependability

more important: Correctness. Readability. Maintainability. Dependability .

Efficiency

Couldn't find

Express Scope

Couldn't find

Function

Couldn't find

Functional Languages

The following essential concepts of modern imperative languages were first developed in functional languages: Generics Polymorphism Type Safety Interactive environment Rich System of types Pattern matching Variables Assignments

Functional Languages

Functional Languages - most easily implemented on an SECD machine where: S: stack of partial results of ongoing computations E: (environment) is a list of value-name associations C: (control) stack of expressions to be evaluated D: (dump) stack of saved prior machine states SECD starts in the "empty" state in which D = ([],[],[exp],[]) Like a Turing computers state machine, the SECD machine transitions among states according to the folloowing six rules If a constant C is at the top of the control(C) stack og expressions, then replace the expression at the top of the stack S with its immediate value. The new state is D = (c::S,E,tail(C),D) IF the top of C is a variable x that is associated with a value in the environment (E) list, then replace the top of Stack S with it associated value. The new state is D = (E(x)::S,E,tail(C),D) If top(C) is an application that must be evaluated, then pop S and push @, expa and expf. The new state is D=(S,E,expf::expa::@::tail(C),D) If top(C) is an abstraction (fn x => exp), then close its value with the current environment. The new state is D = (closure(E,exp,x)::S,E,tail(C),D) If top(C) is @, then pop the function argument off the S stack, and examine the function that was beneath it at top(S) If the function is a primitive function, then apply the function to its argument. The new state is D=(f(top(S))::tail(tail(S)),exp,x),E,tail(C),D) Else the function is a closure of the form closure of the form closure (E1,exp,x). Freeze the current compputation on the dump. The new state is D=([],E1[x<--top(S)][exp],(tail(tail(S)),E,tail(C),D)) If the control list C is empty, examine the dump D: If D is empty, display the results and return to start Else the previous rules computation has finished, and currently D = (S1,E1,C1,D1). Then resume any computation that was previously saved on the dump. The new state is D=(top(S)::S1,E1,C1,D1)

Functional languages abstract machine

The visible parts of an ADT, which include its signature and its operations specifications

Interface

A Java's generic type definition DefPara<T> does not preserve the subtype hierarchy. The Java compiler implements generics more carefully in an erasure mechanism, by type checking the generic method and then actually replacing the generic with the context's required types; e.g., replacing List<Integer> with List.

Generics

A programmer who applies and ADT, but does not create it

Implementation

To acquire a parent's traits, which can be adapted to variety of uses.

Inherit

The Java Virtual Machine (JVM) is the abstract machine that interprets the Java compiler's intermediate byte-code language. It places invoked methods and their parameters on the stack, without hardware-dependent registers. In each compiled class' file, a vtable-like constant pool describes its instance variables, methods, their types, resolved (indices of) names, names of other classes it uses, etc. (Offsets are s-l-o-w-l-y found at runtime, not compile time.) Four different kinds of Java methods are executed as follows: Static methods (associated with a class, not an instance): Only the calling parameters are passed—no reference is made to this. Abstract (virtual) methods: They must be dynamically dispatched, and a reference is passed to the object on which the method is called. Special methods: They must be dynamically dispatched by passing a this pointer to the method's starting address. Referring to the object o in o.m(parameter), the JVM gets the name of m from the constant pool. It looks for the methods m in all other objects. "Code rewriting" changes the o.m(parameter) instruction to the invokevirtual nameIndex instruction, and then to the invokevirtual_quick offset numParms instruction, after each instruction executes. Interface methods: The superclass' completely abstract class is entirely without implementation, and method offsets vary among many (subtype) subclasses' method calls. The JVM loops through all implementation instances of the interface, searching for the method's name index, using the invokeinterface nameIndex instruction. After execution, this code is rewritten as invokeinterface_quick method_name offset. Upon executing this instruction, JVM looks in the vtable to verify the name, index and offset. (If not, it corrects the offset.) Finally it invokes the method.

JVM's Dynamic Dispatch

Type safe Leading O-O languages in the niche Web and mobile programming markets

Java

do preserve subtypes, but they were an early language design error that should have been corrected with the addition of generics, but it wasn't. Instead, the Java compiler inserts dynamic casts that evoke runtime errors, if coders fail to respect type contexts. In their (weak) defense, covariant subtype preserving arrays do provide a limited form of polymorphism.

Java Arrays

Java extends single inheritance for classes but implements multiple inheritance for interfaces. Java's inheritance hierarchy is a tree, and its inheritance relation is a subhierarchy of its subtype hierarchy. Java calls its abstract interface inheritance "mix-in," because it mixes local abstract methods with inherited implementations.

Java Inheritance

Generic Psuedo-language for describing O-Os flexible and extensible data abstraction and its polymorphism, generality and subtype concepts

Java's Design Language

Minimal Instruction set: AND,OR,NOT Turing Complete Express all computable algorithms Supports imperative languages assignments of states

Lambda Calculus

Includes: An alphabet Terms defined over this alphabet Well formed formulae defined over this alphabet

Language of first order logic

Cache, instruction prefetch, branch prediction or pipelining can't optimize abstract machine's performance

Locality of Reference

Less costly than tombstones Alternative issues a key to every new pointer, which matches a lock on the memory it allocates. Deallocation surrenders the key and automatically frees the allocated memory attached to every pointer is a key, which matches to a lock to every memory area allocated in the heap Dereferencing - the abstract machine ensures the key and lock match (if not, raises runtime error) Deallocating - the abstract machine changes its lock to zero, which no pointer can match Cost twice the space of tombstones, but are easily deallocated The allocation and deallocation makes them more speed costly than tombstones

Locks & Keys

Couldn't find

Maintainability

Compact version of Mark&Sweep: memory fragmentation is reduced by moving all live objects linearly into contiguous blocks of similarly aged objects Makes 3 heap passes: Locate live objects new positions Update all external and internal pointers Actually move the objects Proportional to heap size and the number of live objects, runtime is significantly longer than mark&sweep

Mark & Compact

After marking all heap objects "not in use" this collector traverses the root set of active stack pointers recursively depth-first, marking only those objects that currently are "in use". The former are then returned to the free list Only runs when too little memory is available Weaknesses: External fragmentation: large blocks are hard to find Much runtime is spent searching the entire heap Different ages of the objects close together degrade locality of reference

Mark & Sweep Garbage Collector

Dynamic dispatch in C++ is accomplished by subclasses overriding virtual methods. To save runtime, static dispatch also overloads a superclass' non-virtual method in a subclass. Compile-time type matching of those methods' return values and parameters in the context of each invocation resolves the correct method. In CLOS, all methods are globals. Each "multi-method" name is overloaded with many types and implementations. A multi-method implementation is selected at runtime, based on the receiving object's and the arguments' types. CLOS is slow

Method Dispatch

Software architects refer to cohesive clusters of interrelated types (data structures) as modules (packages) All of a modules implementation are hidden and some of its operation s may be hidden Inside the package are many ADT's, each with its own data structures and operations

Modules

In single inheritance, the subclass' vtable is simply a copy of its superclass' vtable, modified to reflect the subclass' shadowed instance variables and overridden methods. Double inheritance presents two problems: How to adapt the subclass' vtable to handle its method calls. How to merge the superclasses' instance variables in the subclass' single vtable. Some popular languages solve this problem with replicated inheritance. After redefining the problem, other popular languages solve it with shared inheritance.\ Shared Multiple Inheritance Only one copy of a virtual (implementation-less) superclass appears in every C++ subclass, even if it is inherited along multiple (diamond) paths. Non-virtual classes must be replicated (see prior slide). Name conflict problem: Methods duplicated in the diamond's middle two (A and B) superclasses must never be accessed there, else the ambiguity would raise a typing error. Dominant redefinition: The method duplicated in A and B above can be accessed in the Bottom subclass without ambiguity. The vtables for shared multiple inheritance in C++ show every class' specific view of the object. The this pointer points at A_Bottom; this+d points at B; and this+e points at Top. (see below.) Combining replicated and shared multiple inheritance is much more complicated.

Multiple Inheritance

Most languages permit only single inheritance. C++ allows subclasses to inherit from multiple superclasses. A compiler must choose, when a subclass references a method f(), which is defined differently in two inherited superclasses A and B. The "diamond problem" of a subclass double-inheriting from superclasses, both of which unknowingly inherit from a single supersuperclass, actually arises frequently.

Multiple Inheritance

Sun Microsystems Java and Apples ObjectiveC also are very popular in their respective niche Web and mobile O-O programming markets Combines: Encapsulation and abstraction Subtypes - a type of compatibility relation, based on objects functionalities Inheritance - the possibility of reusing existing methods in new classes Dynamic method selection

O-O paradigm

The object-oriented (O-O) paradigm creates abstractions in flexible and extensible ways. O-O is useful in class languages (and delegation): Encapsulating data. Controlling compatibility relations between types (subtypes). Reusing code through single and double inheritance. Dynamically dispatching methods. O-O type systems support... Subtype polymorphism. Limited polymorphism in Java's step-child covariant arrays. Overriding covariant and contravariant methods. O-O techniques have improved software development life cycles beyond O-O languages by providing semiformal rules for organizing conceptual objects and operations

O-O paradigm

Couldn't find

Objective C

Denotes more than one object, or when context determines which object is denoted by that name

Overloaded

Couldn't find

Pattern Matching

When memory is nearly exhausted, both heap and stack are almost full, threatening to shut down the garbage collectors use of stack While traversing downward (and upward), the garbage collector reverses pointers behind it, instead of storing its reverse path on the stack This trick requires only two locally stored pointer objects, the current and preceding pointer addresses

Pointer Reversal

Denotes objects of many types with a single name

Polymorphism

Couldn't find

Predicate Relations

Couldn't find

Prolog Deduction

Unlike public and private, protected visibility makes subclasses look the same as their superclasses to a client. Without "protected," superclasses' private code would be invisible to both clients and subclasses. Unfortunately, code maintenance in a "protected" superclass does not automatically propagate to subclasses and must be repeated there. In C++, "protected" affects only class visibility. In Java, "protected" applies to entire packages.

Protected

Couldn't find

Readability

Discover and free any objects that are not currently in use Attached to every object to show how many pointers point at it When an object is allocated, its reference count is initialized to 1 When pointer B's value is assigned to pointer a, the count of b's current object increments, and the count of a's former object decrements Objects with zero counts are garbage. A recursive search for pointers inside the object also clears internal objects counts, all get returned to the free list Circular references cannot be detected or collected as garbage

Reference Counting (Garbage Collectors)

Users may rely upon abstract specifications stk = create_stack() creates and empty stack push(stk, element) places and element on the stack element = pop(stk) removes an element from the top of the non-empty stack empty(stk) is true if and only if the stack is empty Property: Two correct implementations Of a single ADT specification Cannot be distinguished By the ADT's clients Replacing ADT's correct implementation with some other correct implementation causes no new errors in client software

Representation Independence

The superclass' instance variable also may be replaced with the subclasses' local variable, with identical name and type.

Shadow Variable

Declarations of all ADT operations names, parameter types and returned types, which the ADT offers to its clients

Signature

Simula - origin of the O-O paradigm in the 60s Smalltalk - origin of O-O paradigm in the 70s O-O language pioneers

Simula & Smalltalk

subtype relation, every instance a of class A has all of the superclasses of class A as its type.

Subtype Relation

T is a subtype of S, when the interface of S is a subset of the interface of T (see top p.288). Your textbook provides a peculiar example of a subclass inheriting two different superclasses and subsequently overriding all of their methods. Rest assured, that doesn't happen much in practice. The derived classes (subclasses) of C++ introduce its inheritance relation. And they introduce the subtype relation, when those derived classes declare their base classes (superclasses) public. (If not public, the subtype relation disappears.)

Subtype relation

Superclass- Java's name for a software designer's prototype class that programmers use with minimal editing. Subclass- A class that inherits the software designer's prototype and adds an instance variable or a method of its own. type T becomes a smaller subtype of the all-inclusive type S. But the user interface of subclass S is a subset of its inherited superclass T. (Note the inversion.)

Superclass & Subclass

The terms over a signature sigma and over the set of variables V are defined inductively by A variable in V is a term If f in sigma is a function symbol if arity n and t1,...,tn are terms, then f(t1,...,tn) is a term Examples: Arithmetic expression a+b-c is a term Strings, binary trees and lists are terms Also the functions f(a,b),g(a,X) and h(f(a,b),Y)

Term

Separately allocated space in a reserved memory "cemetery" Force double indirect referencing of allocated memory and continue pointing at "dead" memory when it is deallocated Abstract machines save memory address in a tombstone, forcing programmers pointer to access memory double indirectly Dereferencing - when one pointer is assigned to another it is the contents of the pointer that is modified Deallocating - tombstone is marked to indicate that its memory is dead Double-indirection access to a great many small data items inflicts a high runtime cost. Allocating tombstones in protected memory consumes costly space A small garbage collector may trade speed for space by recycling used tombstones

Tombstones

Process of attributing a type to an expression, when a programming language does not require explicit type declarations The process sweeps through the tree three times: Copy all explicit types from the compilers symbol table and source code to nodes in the tree Use equality constraints to determine types of all expressions; e.g. a+1 and + are int because 1 is int Use the unification algorithm to resolve any remaining ambiguities

Type Inference Process

Set of constructs and mechanisms that define and regulate its use of types

Type System

Couldn't find

Variables

Virtual function table. The virtual table is a lookup table of functions used to resolve function calls in a dynamic/late binding manner. JVM looks in the vtable to verify the name, index and offset. Pointers to all methods (along with their parameter and returned value types) gathered for each class definition before runtime. (A.K.A. constant pool.) Accessing a method via the vtable costs only two indirect accesses at runtime.

Vtable

enables creation of any type of stack (i.e., Stack<?> is the supertype of every specific stack), but that type must be respected thereafter. Java's compiler assumes that two wildcards in the same construct are completely distinct variables. One "unknown" (the '?' character) substituted for a type in a subclass definition enables the compiler to adapt the subclass to any type context.

Wildcard

Clear the count from inside the Counter class

this.x = 0

Obtain the private counts current value

y = Counter.get(x)

Obtain a public counts current value

z = Counter.x


संबंधित स्टडी सेट्स

CH 10 Planning for Contengencies

View Set

Chapter 7- Hair and Scalp Propertie👍

View Set

Chapter 8: Corporate Strategy - vertical integration & diversification

View Set

ITIL - Chapter 7 Service Operations

View Set

Unit 4: Recordation, Title Insurance, and Settlement (Units 8, 10, 17, 21)

View Set