[SOLVED] CS c# c++ compiler cache python chain flex Java Abstraction in Software

$25

File Name: CS_c#_c++_compiler_cache_python_chain_flex_Java_Abstraction_in_Software.zip
File Size: 668.82 KB

5/5 - (1 vote)

Abstraction in Software

CPSC 3200 OODevelopment

Midterm Review

C#
Microsoft,2001
Proprietary Java (precursor: Visual J++)
.NET platform
Goals similar to Java
Portability
Safety (Managed Code)
Garbage collection
Run-time checks
Pointer construct only viable in UNSAFE code
delegate construct (like function pointer)
+ Programmer Productivity

Differences from Java
Limited operator overloading
Getter/setter (properties)
No checked exceptions
Choice of method binding

CPSC 3200Dingle

What is the computing environment in the 1990s?

Efficiency not a concern
processors cheaper and faster
more cache

BUT memory access bottleneck

Faster development time
BUT Java 2X or more slower than C++

CPSC 3200Dingle

C++
Bjarne Stroustrup, ATT Bell labs, 1985
OO extension of C => backward compatible with C
Support all C features
C code compiled by C++ compiler
Efficiency still primary goal
pay only for what you use
Stack allocation default
Static binding default
HL abstraction with low-level manipulations permitted
=>the pointer construct
Quickly became industry standard
Not considered safe
Omission of run-time checks
Memory management problems

3
3

C++ 11/14
Backward compatible with C++ 98
Emphasis on improved support for
Performance=> Move semantics
Stable Memory=> Smart Pointers
Multithreading
Generics
Appeal
Like other PLs, move closer to Python & functional languages
Support for lambda and regular expressions
Software Construction for Longevity
Self-documenting code & Design consistency
CPSC 3200Dingle

C# vs C++
What are the major differences?
Relevant to memory?
OOD?

How do these difference impact?
Client?
Class design?
CPSC 3200Dingle

C# vs C++ differences
Object allocation
All C# objects allocated via new on the heap
C++ objects allocated on stack by default
C++ heap objects allocated via new and addressed via pointers
Object deallocation
C# implicit deallocation garbage collector
C++ automaticdeallocation of stack objects
Compiler patches in calls to destructors of all objects on stack frame
C++ explicit deallocation of heap objects via delete
Copying
Shallow copying (of addresses) yields aliases
C++ class design requires explicit decisions wrt copying
Modern C++ should define move semantics alongside deep copying

CPSC 3200Dingle

C# vs C++ difference
C# zero initializes data;C++ does not.Why?
Arrays
No bounds checking in C++. Why?
=> Must check indices for security
C# array of objects == array of references
C++ array of objects depends on provision of no-argument constructor

Polymorphism
Both use static binding as default (for efficiency)
=> Must tag methods as virtual to get dynamic binding
C++ clients must use pointers.Why?
CPSC 3200Dingle

Elements of Class Design
Constructor(s)
Set initial state
Allocate resources
=> No need for initialize()
Accessors
get() should be const
Controlled peek inside class
Mutators minimize
set()
Controlled alteration of state
Check values
discard out-of-bounds values
provide default values
Key TYPE functionality
Public methods that provide client with expected functionality
Private/protected methods to support internal control & type consistency
DingleCPSC 3200

Structural Decomposition
=>Relationships
Has-AComposition
Holds-AContainment
Is-AInheritance

When to use each type of relationship?
What are the effects/costs/benefits of each design?
What is the impact of each relationship on:
CLIENT?
CLASS DESIGNER?
CPSC 3200Dingle

CPSC 3200Dingle
Copying: Key Design Decision
NO DECISION => Aliasing (Shallow Copy)
Bitwise copy => address copied
DANGER

Suppress Copying
C++: private copy constructor and operator=
Support (Deep) Copying
C++: DEFINE public copy constructor and operator=
C#: DEFINE public ShallowCopy() and DeepCopy() methods
C++11: MOVE SEMANTICS
Design for efficiency WHEN DEEP Copying (saves new/delete)
Use && to flag compiler
Copying replaced with ownership transfer by compiler
When appropriate (TEMPORARIES)
Enhances performance (does not yield persistent unintended aliases)

10
Show memory diagrams

C# Cloning Design: Internal Type reclamation
public class uCopy
{private anotherClassrefd;

private object Clone()
{uCopylocal = this.MemberwiseClone() as uCopy;
local.refd = this.refd.Clone() as anotherClass;
return local;
}

public uCopy ShallowCopy()
{return (uCopy)this.MemberwiseClone(); }

// internal type reclamation
public uCopy DeepCopy()
{uCopy u2 = this.Clone() as uCopy;

}
}

Dingle 3200

The other class also needs to have implemented Clone() and used ICloneable interface
11

Suppress Copying

Deep copying more expensive than shallow copying.

Shallow copying may lead to data corruption.

Copying may be suppressed when undesirable
Do NOT duplicate large registries (hash tables, etc. )
Preserve sole ownership of resource
Data integrity
Generation of temporaries
Transient use
Functionality using resource may not be exercised

Dingle 3200

12

C++deep copying
// private utility for copying
void noLeak::copy(const noLeak& src)
{size = src.size;
heapData = new int[size];
for (int k = 0; k < size; k++)heapData[k] = src.heapData[k];} // copy constructor supports call by valuenoLeak::noLeak(const noLeak& src){copy(src);} // overloaded= supports deep copying; check for self-assignment noLeak& noLeak::operator=(const noLeak& src){if (this = = &src)return *this;// guard clausedelete[] heapData;copy(src);return *this;}Dingle 3200Return type on = could be void since it simply works on itself, but then no chaining is allowed (because nothing is returned)13C++ 11move semantics: denoted by &&// move constructor supports efficient call by value//heap memory transferred//caller loses access to heap memorynoLeak::noLeak(noLeak&& src){// simply copy size and address to heap memorysize = src.size;heapData = src.heapData;// zero out callers handle to heap memorysrc.size = 0; src.heapData = nullptr;} Dingle 3200move constructor & move assignment operator14C++ 11move semantics: denoted by &&// move assignment exchanges ownership// reference returned to support chained assignmentnoLeak& noLeak::operator=(noLeak&& src){swap( size, src.size);// LHS swaps ownership with RHS// no need for distinct copy if RHS goes out of scope swap( heapData, src.heapData);return*this;}Dingle 3200move constructor & move assignment operator15Structural Design DetailsCardinality: How many subObjects?1:1 for inheritance1-many for compositionVariable for containmentOwnershipisA: Child owns Parent component => parent component may NOT be released
hasA: Composing object may stub out/replace subObject
holdsA: None, usually, since containers are mostly just a data store
Lifetime
1:1 for inheritance => parent component constructed before child component
variable by design for composition
Association
Permanent for inheritance
Possibly transient for composition
Temporary for containment
Copyright@2014Taylor & Francis Adair Dingle All Rights Reserved

Composition

Encapsulation
=> Class design starts with complete internal control

Class designer may choose what to
Vary
Expose
=> More responsibility, More control
CPSC 3200Dingle

Dependency Injection
Dependencies must go somewhere

Selective externalization of resource
=> increase cllent responsibility
=> increase class design for error response
Three approaches more than one may be used in a class design:
Constructor
Set once
Stable
Property (Setter)
Flexible
Increased dependency on client
Method (Interface)
Isolated

Dingle 3200

Inheritance

Substitutability
Child object may serve as substitute for parent
PARENT interface defines utility of relationship

Polymorphism
Type extensibility
Heterogeneous collections
CPSC 3200Dingle

Static vs. Dynamic Binding
Static binding
translates function calls directly into jump statements
function invoked at the point of call cannot vary
No run-time overhead
No run-time flexibility
Dynamic binding
postpones function call resolution until run-time
function invoke at the point of call can vary
great flexibility
Run-time overhead
supports polymorphism and heterogeneous collections.
Copyright@2014Taylor & Francis Adair Dingle All Rights Reserved

C#/C++dynamic binding
C#
Class design only
Add keyword virtual to method in base class
Add keyword override to method in derived class

C++
Class design
Add keyword virtual to method in base class
C++11 keyword override for method in derived class: OPTIONAL
Application code
Use base class pointers

CPSC 3200Dingle

Heterogeneous Collection
Class hierarchy uses virtual functions
variant behavior (based on subtype)

Traversal of heterogeneous collection
Yields streamline execution of varying functionality
Masks subtype construction and evaluation

Type extensibility supported
Stable client code even if new subtype(s) added

Copyright@2014Taylor & Francis Adair Dingle All Rights Reserved

/docProps/thumbnail.jpeg

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS c# c++ compiler cache python chain flex Java Abstraction in Software
$25