Podcast
Questions and Answers
What term describes calls to methods in object-oriented programming?
What term describes calls to methods in object-oriented programming?
- Instructions
- Signals
- Commands
- Messages (correct)
How can a subclass differ from its parent class?
How can a subclass differ from its parent class?
- By limiting the access of inherited methods
- By modifying private variables
- By redefining class variables
- By adding variables or methods (correct)
What is indicated by the term 'dynamic binding' in object-oriented programming?
What is indicated by the term 'dynamic binding' in object-oriented programming?
- Binding that occurs when a polymorphic variable references its methods (correct)
- Binding that requires explicit type declaration
- Binding to a specific object instance at compile time
- Binding that prevents method overriding
Which of the following best describes encapsulation in the context of inheritance?
Which of the following best describes encapsulation in the context of inheritance?
Which variables are unique to each instance of a class?
Which variables are unique to each instance of a class?
What is a disadvantage of using inheritance for code reuse?
What is a disadvantage of using inheritance for code reuse?
What component of a message allows it to define the action to be executed?
What component of a message allows it to define the action to be executed?
What happens when a class overrides a method from its parent class?
What happens when a class overrides a method from its parent class?
Which feature of object-oriented programming allows a class to inherit properties and behavior from another class?
Which feature of object-oriented programming allows a class to inherit properties and behavior from another class?
What is the relationship between a subclass and a superclass in object-oriented programming?
What is the relationship between a subclass and a superclass in object-oriented programming?
In which programming language mentioned is object-oriented programming fully supported?
In which programming language mentioned is object-oriented programming fully supported?
Which of the following concepts relates closely to the ability of different classes to be treated as instances of the same class through a common interface?
Which of the following concepts relates closely to the ability of different classes to be treated as instances of the same class through a common interface?
What are the instances created from classes called in object-oriented programming?
What are the instances created from classes called in object-oriented programming?
Which of the following languages does not primarily support multiple programming paradigms including object-oriented programming?
Which of the following languages does not primarily support multiple programming paradigms including object-oriented programming?
What is a significant advantage of using inheritance in object-oriented programming?
What is a significant advantage of using inheritance in object-oriented programming?
What term is used to describe classes that are reused with minor modifications to existing abstract data types (ADTs)?
What term is used to describe classes that are reused with minor modifications to existing abstract data types (ADTs)?
What is a key advantage of having all objects allocated from the heap in dynamic object management?
What is a key advantage of having all objects allocated from the heap in dynamic object management?
What is a consequence of having objects that are stack dynamic in terms of subtype behavior?
What is a consequence of having objects that are stack dynamic in terms of subtype behavior?
What is one of the limitations related to nested classes in Smalltalk?
What is one of the limitations related to nested classes in Smalltalk?
Which statement regarding dynamic and static binding is true?
Which statement regarding dynamic and static binding is true?
When a subclass object is created, how are parent class members treated in Smalltalk?
When a subclass object is created, how are parent class members treated in Smalltalk?
What is one defining feature of Smalltalk as an object-oriented programming language?
What is one defining feature of Smalltalk as an object-oriented programming language?
What is the implication of implementation inheritance in Smalltalk?
What is the implication of implementation inheritance in Smalltalk?
How does Smalltalk handle deallocation of objects?
How does Smalltalk handle deallocation of objects?
An abstract class can be instantiated.
An abstract class can be instantiated.
Dynamic binding is less efficient with single inheritance compared to multiple inheritance.
Dynamic binding is less efficient with single inheritance compared to multiple inheritance.
A derived class must behave the same as its parent class object to be considered a subtype.
A derived class must behave the same as its parent class object to be considered a subtype.
Multiple inheritance allows a new class to inherit from a single class only.
Multiple inheritance allows a new class to inherit from a single class only.
Everything is considered an object in a complete typing system.
Everything is considered an object in a complete typing system.
Adding objects to a typing system results in faster operations on simple objects.
Adding objects to a typing system results in faster operations on simple objects.
The primary disadvantage of multiple inheritance is its convenience.
The primary disadvantage of multiple inheritance is its convenience.
Subclass can add new variables and methods in a compatible way.
Subclass can add new variables and methods in a compatible way.
All binding of messages to methods in Smalltalk is static.
All binding of messages to methods in Smalltalk is static.
In Smalltalk, type checking is performed at compile time.
In Smalltalk, type checking is performed at compile time.
C++ evolved from C and SIMULA 67.
C++ evolved from C and SIMULA 67.
Constructors and destructors are features of Smalltalk but not C++.
Constructors and destructors are features of Smalltalk but not C++.
Private access controls allow visibility only within the class and its friends in C++.
Private access controls allow visibility only within the class and its friends in C++.
All members inherited through private derivation in C++ become public in the subclasses.
All members inherited through private derivation in C++ become public in the subclasses.
A class in C++ must be a subclass of another class to be valid.
A class in C++ must be a subclass of another class to be valid.
Smalltalk introduced the concept of graphical user interfaces.
Smalltalk introduced the concept of graphical user interfaces.
In C++, objects allocated from the stack are automatically deleted when they go out of scope.
In C++, objects allocated from the stack are automatically deleted when they go out of scope.
C++ allows for multiple inheritance, while Smalltalk does not support this feature.
C++ allows for multiple inheritance, while Smalltalk does not support this feature.
Dynamic binding in C++ always results in faster method calls compared to static binding.
Dynamic binding in C++ always results in faster method calls compared to static binding.
In Java, all objects are created on the heap and managed by reference variables.
In Java, all objects are created on the heap and managed by reference variables.
The finalize method in Java is called after an object is garbage collected.
The finalize method in Java is called after an object is garbage collected.
C++ statically binds methods at runtime for improved performance.
C++ statically binds methods at runtime for improved performance.
In C++, a Circle object allocated from the heap is treated the same as a Circle object allocated from the stack.
In C++, a Circle object allocated from the heap is treated the same as a Circle object allocated from the stack.
Smalltalk is significantly faster than C++ due to its dynamic type checking capabilities.
Smalltalk is significantly faster than C++ due to its dynamic type checking capabilities.
C# supports both single and multiple inheritance.
C# supports both single and multiple inheritance.
In C#, a method that is inherited can be overridden in the derived class by marking it with the keyword override.
In C#, a method that is inherited can be overridden in the derived class by marking it with the keyword override.
All variables in Ruby are strictly typed references to their respective classes.
All variables in Ruby are strictly typed references to their respective classes.
Dynamic binding in C# requires that the base class method is marked abstract.
Dynamic binding in C# requires that the base class method is marked abstract.
In Ruby, access to data members is private by default and cannot be changed.
In Ruby, access to data members is private by default and cannot be changed.
C# allows nested classes that function like Java's non-static classes.
C# allows nested classes that function like Java's non-static classes.
In C#, a subclass is considered a subtype only if all members of the parent class are public.
In C#, a subclass is considered a subtype only if all members of the parent class are public.
Method definitions in Ruby are non-executable and must be declared before use.
Method definitions in Ruby are non-executable and must be declared before use.
Access controls to inherited methods can differ from those in the parent class.
Access controls to inherited methods can differ from those in the parent class.
All variables in Ruby are statically typed and non-polymorphic.
All variables in Ruby are statically typed and non-polymorphic.
A programming language that supports reflection allows programs to modify their types at compile time.
A programming language that supports reflection allows programs to modify their types at compile time.
Static data structures in Ruby are built at runtime to manage instance variables.
Static data structures in Ruby are built at runtime to manage instance variables.
Dynamically bound methods in Ruby require entries in the Class Instance Record (CIR).
Dynamically bound methods in Ruby require entries in the Class Instance Record (CIR).
Reflection involves the process of a program observing its own metadata.
Reflection involves the process of a program observing its own metadata.
Ruby fully supports multiple inheritance.
Ruby fully supports multiple inheritance.
The process of a program examining its behavior is known as introspection.
The process of a program examining its behavior is known as introspection.
Reflection in Java allows access to private fields and methods of a class.
Reflection in Java allows access to private fields and methods of a class.
The getClass method is used in Java to return the class object of an object.
The getClass method is used in Java to return the class object of an object.
In C#, the getType function serves the same purpose as Java's getClass method.
In C#, the getType function serves the same purpose as Java's getClass method.
The System.Reflection.Emit namespace in C# allows for the creation of intermediate code and putting it into an assembly.
The System.Reflection.Emit namespace in C# allows for the creation of intermediate code and putting it into an assembly.
Java provides functionality to create intermediate code and add it to an assembly.
Java provides functionality to create intermediate code and add it to an assembly.
Using reflection can improve the performance of a software application.
Using reflection can improve the performance of a software application.
Reflection can lead to code that is nonportable when run under a security manager.
Reflection can lead to code that is nonportable when run under a security manager.
The getDeclaredMethod retrieves all methods of a class, including private ones, in Java.
The getDeclaredMethod retrieves all methods of a class, including private ones, in Java.
The Electronics class directly inherits from the Product class.
The Electronics class directly inherits from the Product class.
A class in Java cannot extend more than one class at the same time.
A class in Java cannot extend more than one class at the same time.
The displayInfo method in the Product class is inherited but not overridden in the Electronics class.
The displayInfo method in the Product class is inherited but not overridden in the Electronics class.
The ArrayList can be used to store products in the shopping cart implementation.
The ArrayList can be used to store products in the shopping cart implementation.
When a method is overridden in a subclass, the original method from the parent class cannot be called.
When a method is overridden in a subclass, the original method from the parent class cannot be called.
The ShoppingCart class utilizes polymorphism for handling different payment methods.
The ShoppingCart class utilizes polymorphism for handling different payment methods.
The method makePayment in the CreditCardPayment class requires a double parameter for the payment amount.
The method makePayment in the CreditCardPayment class requires a double parameter for the payment amount.
The ShoppingCart class is designed to manage a list of products using an array.
The ShoppingCart class is designed to manage a list of products using an array.
In Java, an interface allows a class to implement multiple behaviors.
In Java, an interface allows a class to implement multiple behaviors.
The Product class has public fields that allow unrestricted access from other classes.
The Product class has public fields that allow unrestricted access from other classes.
The GameObject class defines both move and render methods as pure virtual methods.
The GameObject class defines both move and render methods as pure virtual methods.
In the PaymentDemo class, the makePayment method can only be called on CreditCardPayment instances.
In the PaymentDemo class, the makePayment method can only be called on CreditCardPayment instances.
A derived class in C++ must implement all virtual methods defined in its base class.
A derived class in C++ must implement all virtual methods defined in its base class.
The displayCart method in the ShoppingCart class prints the contents of the cart to the console.
The displayCart method in the ShoppingCart class prints the contents of the cart to the console.
The removal of a product from the ShoppingCart returns a boolean indicating success.
The removal of a product from the ShoppingCart returns a boolean indicating success.
What is the primary purpose of the Electronics class in the given Java e-commerce system?
What is the primary purpose of the Electronics class in the given Java e-commerce system?
Which of the following best describes the inheritance demonstrated in the Product class and its subclass?
Which of the following best describes the inheritance demonstrated in the Product class and its subclass?
In the provided code, what would be the output of the displayInfo method for the genericProduct instance?
In the provided code, what would be the output of the displayInfo method for the genericProduct instance?
Which feature of the Java e-commerce system allows the shopping cart to manage multiple products?
Which feature of the Java e-commerce system allows the shopping cart to manage multiple products?
Which of the following actions can be performed on the shopping cart as described in the e-commerce system?
Which of the following actions can be performed on the shopping cart as described in the e-commerce system?
Which of the following methods would allow a user to remove a product from the ShoppingCart?
Which of the following methods would allow a user to remove a product from the ShoppingCart?
What is the advantage of using polymorphism in payment processing?
What is the advantage of using polymorphism in payment processing?
In the context of the ShoppingCart class, what does encapsulation primarily protect?
In the context of the ShoppingCart class, what does encapsulation primarily protect?
What will be printed when a product that is not in the cart is attempted to be removed?
What will be printed when a product that is not in the cart is attempted to be removed?
Which of the following methods in the GameObject class is a pure virtual method?
Which of the following methods in the GameObject class is a pure virtual method?
What is required for a class in Java to implement an interface like Payment?
What is required for a class in Java to implement an interface like Payment?
How does the design of the ShoppingCart class ensure data integrity?
How does the design of the ShoppingCart class ensure data integrity?
What feature allows different payment methods to be treated uniformly in the payment system?
What feature allows different payment methods to be treated uniformly in the payment system?
Which class should be derived from GameObject if new functionality like collision detection is to be added?
Which class should be derived from GameObject if new functionality like collision detection is to be added?
What is the purpose of the virtual destructor in the GameObject class?
What is the purpose of the virtual destructor in the GameObject class?
Flashcards
Message Protocol
Message Protocol
The collection of methods available for an object.
Message
Message
A call to an object's method, containing method name and object.
Inheritance
Inheritance
A class acquiring characteristics of a parent class.
Access Controls (in inheritance)
Access Controls (in inheritance)
Signup and view all the flashcards
Method Overriding
Method Overriding
Signup and view all the flashcards
Class Variable
Class Variable
Signup and view all the flashcards
Instance Variable
Instance Variable
Signup and view all the flashcards
Dynamic Binding
Dynamic Binding
Signup and view all the flashcards
Stack-Dynamic Objects
Stack-Dynamic Objects
Signup and view all the flashcards
Heap-Dynamic Objects
Heap-Dynamic Objects
Signup and view all the flashcards
Object Slicing
Object Slicing
Signup and view all the flashcards
Static Binding
Static Binding
Signup and view all the flashcards
Nested Classes
Nested Classes
Signup and view all the flashcards
Implicit Initialization
Implicit Initialization
Signup and view all the flashcards
Explicit Initialization
Explicit Initialization
Signup and view all the flashcards
Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)
Signup and view all the flashcards
Polymorphism
Polymorphism
Signup and view all the flashcards
Abstract Data Types (ADTs)
Abstract Data Types (ADTs)
Signup and view all the flashcards
Classes
Classes
Signup and view all the flashcards
Objects
Objects
Signup and view all the flashcards
Methods
Methods
Signup and view all the flashcards
Derived Class (Subclass)
Derived Class (Subclass)
Signup and view all the flashcards
Abstract Method
Abstract Method
Signup and view all the flashcards
Abstract Class
Abstract Class
Signup and view all the flashcards
Single Inheritance
Single Inheritance
Signup and view all the flashcards
Multiple Inheritance
Multiple Inheritance
Signup and view all the flashcards
Objects on the Heap
Objects on the Heap
Signup and view all the flashcards
Objects on the Stack
Objects on the Stack
Signup and view all the flashcards
What is C++?
What is C++?
Signup and view all the flashcards
C++ Inheritance
C++ Inheritance
Signup and view all the flashcards
C++ Access controls
C++ Access controls
Signup and view all the flashcards
Private Derivation (C++)
Private Derivation (C++)
Signup and view all the flashcards
Public Derivation (C++)
Public Derivation (C++)
Signup and view all the flashcards
C++ Constructor & Destructor
C++ Constructor & Destructor
Signup and view all the flashcards
C++'s Mixed Type System
C++'s Mixed Type System
Signup and view all the flashcards
C++'s Advantages
C++'s Advantages
Signup and view all the flashcards
Polymorphism in C++
Polymorphism in C++
Signup and view all the flashcards
Static Binding in C++
Static Binding in C++
Signup and view all the flashcards
Dynamic Binding in C++
Dynamic Binding in C++
Signup and view all the flashcards
Heap-Dynamic Objects in Java
Heap-Dynamic Objects in Java
Signup and view all the flashcards
Java's 'finalize' Method
Java's 'finalize' Method
Signup and view all the flashcards
Wrapper Classes in Java
Wrapper Classes in Java
Signup and view all the flashcards
Evaluation of OOP Support in C++ vs. Smalltalk
Evaluation of OOP Support in C++ vs. Smalltalk
Signup and view all the flashcards
How Java Differs from C++
How Java Differs from C++
Signup and view all the flashcards
Overriding Methods in C#
Overriding Methods in C#
Signup and view all the flashcards
Calling Parent Class Methods in C#
Calling Parent Class Methods in C#
Signup and view all the flashcards
C# Abstract Methods
C# Abstract Methods
Signup and view all the flashcards
Ruby Message Passing
Ruby Message Passing
Signup and view all the flashcards
Ruby Class Definitions
Ruby Class Definitions
Signup and view all the flashcards
Ruby Method Access Controls
Ruby Method Access Controls
Signup and view all the flashcards
What does a CIR store?
What does a CIR store?
Signup and view all the flashcards
How are subclass variables stored in Ruby?
How are subclass variables stored in Ruby?
Signup and view all the flashcards
What is dynamic binding?
What is dynamic binding?
Signup and view all the flashcards
What is the 'vtable' in dynamic binding?
What is the 'vtable' in dynamic binding?
Signup and view all the flashcards
Define 'reflection' in programming.
Define 'reflection' in programming.
Signup and view all the flashcards
What is 'metadata' in reflection?
What is 'metadata' in reflection?
Signup and view all the flashcards
What is 'introspection' in reflection?
What is 'introspection' in reflection?
Signup and view all the flashcards
Define 'intercession' in the context of reflection.
Define 'intercession' in the context of reflection.
Signup and view all the flashcards
Reflection (in software)
Reflection (in software)
Signup and view all the flashcards
Reflection Uses
Reflection Uses
Signup and view all the flashcards
Java Reflection
Java Reflection
Signup and view all the flashcards
C# Reflection
C# Reflection
Signup and view all the flashcards
Reflection Downside: Performance
Reflection Downside: Performance
Signup and view all the flashcards
Reflection Downside: Security
Reflection Downside: Security
Signup and view all the flashcards
Reflection Downside: Portability
Reflection Downside: Portability
Signup and view all the flashcards
Reflection Tradeoffs
Reflection Tradeoffs
Signup and view all the flashcards
Product Inheritance
Product Inheritance
Signup and view all the flashcards
Shopping Cart Implementation
Shopping Cart Implementation
Signup and view all the flashcards
ShoppingCart Class
ShoppingCart Class
Signup and view all the flashcards
Product Class
Product Class
Signup and view all the flashcards
Electronics Class
Electronics Class
Signup and view all the flashcards
Polymorphism in Payments
Polymorphism in Payments
Signup and view all the flashcards
Payment Interface
Payment Interface
Signup and view all the flashcards
CreditCardPayment Class
CreditCardPayment Class
Signup and view all the flashcards
PayPalPayment Class
PayPalPayment Class
Signup and view all the flashcards
Inheritance (C++)
Inheritance (C++)
Signup and view all the flashcards
GameObject Class (C++)
GameObject Class (C++)
Signup and view all the flashcards
Enemy Class (C++)
Enemy Class (C++)
Signup and view all the flashcards
Polymorphism through Payment
Polymorphism through Payment
Signup and view all the flashcards
Inheritance Hierarchy (C++)
Inheritance Hierarchy (C++)
Signup and view all the flashcards
Study Notes
Chapter 12 Topics
- OOP Languages support procedural and data-oriented programming (e.g., C++) or functional programming (e.g., CLOS).
- Newer languages may not support other paradigms (e.g., Java, C#).
- Some languages are purely object-oriented (e.g., Smalltalk, Ruby).
- Functional languages may support OOP, but aren't discussed here.
Object-Oriented Programming
- Three major language features are:
- Abstract data types (Chapter 11)
- Inheritance
- Polymorphism
- Inheritance is central to OOP and supporting languages.
Inheritance
- Productivity increases come from code reuse.
- ADTs (Abstract Data Types) are reusable but often require changes.
- Inheritance defines new classes in terms of existing ones, letting them inherit common parts.
- Inheritance addresses code reuse after minor changes and the definition of classes in a hierarchy.
Object-Oriented Concepts
- ADTs are called classes.
- Class instances are objects.
- A class that inherits is a derived class or subclass.
- Classes from which another class inherits are parent classes or superclasses.
- Subprograms defining operations on objects are called methods.
- Calls to methods are messages.
- An object's complete set of methods is its message protocol or message interface.
- Messages have a method name and destination object.
- A class often inherits all entities of its parent class.
- Inheritance can be complex due to access controls to encapsulated entities– a class can hide entities from subclasses or clients.
- A class can modify an inherited method by overriding it.
Object-Oriented Concepts (continued)
- Several ways classes differ from their parent: Adding variables/methods, modifying inherited method behavior, and defining private variables/methods.
Object-Oriented Concepts (continued)
- Two kinds of variables in a class: Class variables (one per class); Instance variables (one per object).
- Methods in a class include: Class methods (accept messages to the class); Instance methods (accept messages to objects).
- Disadvantages of inheritance: creates dependencies amongst classes that increase maintenance efforts.
Dynamic Binding
- A polymorphic variable can reference objects of the class and any descendants.
- Dynamic binding occurs when methods are called through polymorphic variables in a class hierarchy.
- This allows for more easily extended software systems during development and maintenance.
Dynamic Binding Concepts
- An abstract method only defines a protocol (without implementation).
- An abstract class contains at least one virtual method.
- An abstract class cannot be instantiated.
Design Issues for OOP Languages
- Topics of discussion in OOP languages: Exclusivity of objects, relationship between subclasses and subtypes, single/multiple inheritance, object allocation/deallocation, dynamic/static binding, nested classes, object initialization.
The Exclusivity of Objects
- The advantage of everything being an object is elegance and purity.
- The disadvantage of these systems is the relatively slow operations on simple objects
- Adding objects to an imperative-style typing system provides fast operations on simple objects but results in a confusing type system.
Are Subclasses Subtypes?
- The relationship between a parent class and a subclass object is an "is-a" relationship.
- If a derived class is "is-a" parent class, subclass objects should behave similarly to parent class objects.
- A derived class is a subtype if it has an "is-a" relationship with its parent.
- Subclasses can add variables/methods but must override parent methods "compatibly."
- Subclasses inherit implementation, but subtypes inherit both interface and behavior.
Single and Multiple Inheritance
- Multiple inheritance allows new classes to inherit from two or more classes.
- Disadvantages of multiple inheritance: Increased complexity, potential inefficiency, dynamic binding.
- In general, in cases where appropriate, multiple inheritance may be useful in cases where such relationships benefit it.
Allocation and Deallocation of Objects
- Objects can be allocated from the runtime stack following the ADT paradigm, from heap storage or explicitly.
- If objects are stack-based, a problem exists with subtypes (object slicing).
- Deallocation can be explicit or implicit.
Dynamic and Static Binding
- Should binding of messages to methods be dynamic?
- If none are dynamic, the advantages of dynamic binding are lost; if all are dynamic, it's inefficient.
- Design should allow the user to specify.
Nested Classes
- Define a new class that's needed only by one class.
- Can the new class be nested inside the class that needs it?
- Issues: visibility facilities of the nesting class to the nested class or vice versa.
Initialization of Objects
- Are objects initialized to values on creation?
- Implicit or explicit initialization of objects.
- Issues with parent class member initialization when creating a subclass object.
Support for OOP in Smalltalk
- Smalltalk is a pure OOP language.
- Everything is an object.
- Objects use local memory to store data.
- Computing occurs through objects sending messages to other objects.
- Uses a heap to allocate objects.
- Deallocation is implicit.
- Classes cannot be nested in other classes.
Support for OOP in Smalltalk (continued)
- A Smalltalk subclass inherits all instance variables, methods (instance and class), and parent class superclass.
- All subclasses are subtypes.
- Inheritance is implemented.
- Doesn't support multiple inheritance.
- Dynamic binding is fundamental, looking for a method in an object, its superclass, etc.
- Evaluation: Simple syntax and high power, but slower compared to compiled imperative languages.
Support for OOP in C++
- Evolved from C and SIMULA 67.
- Widely used OOP language.
- Mixed type system.
- Constructors/destructors present.
- Access controls (private, public, protected) for class entities.
- Class doesn't need to inherit from another class.
Support for OOP in C++ (continued)
- Access controls for members: Private (visible to members and friends); Public (visible to subclasses and clients); Protected (visible to class and subclasses; not clients).
- Inheritance can be "private."
- Public derivation passes public and protected members to subclasses as public/protected.
- Reexportation using the scope resolution operator permits accessing a private member in a child class.
Support for OOP in C++ (continued)
- Multiple inheritance is available.
- Dynamic binding by defining methods to be virtual.
- Pure virtual functions have no definition, and have no default behavior.
- A class with a pure virtual function is abstract.
- If objects are allocated from the stack, operations differ.
- Evaluation: extensive access controls, multiple inheritance, and dynamic binding make it a very useful language.
Support for OOP in Java
- Close relationship to C++.
- Data (except primitives) are objects.
- Primitive types have wrapper classes.
- Objects are heap-dynamic.
- Finalize method called when garbage collection reclaims storage.
- Interfaces include only method declarations.
- Methods can be final.
- All subclasses are subtypes.
Support for OOP in Java (continued)
- Dynamic binding is used unless a method is declared final.
- Methods are static or private to avoid overriding.
- Nested classes (inner, static, or local are hidden in package) are supported.
- Evaluation: OOP design decisions similar to C++ but with no procedural programming support, parentless classes, and dynamic method binding (uses interfaces to support multiple inheritance).
Support for OOP in C#
- Supports OOP mechanisms similar to Java.
- Includes both classes and structs.
- Classes similar to Java's; structs are less powerful, stack-dynamic constructs without inheritance.
Support for OOP in C# (continued)
- Syntax for defining classes similar to C++.
- Inherited methods in derived classes may be marked 'new' for replacement- otherwise, the original parent method can be invoked using "base.Draw()."
- Subclasses are subtypes if no members are private on the parent class.
- Only single inheritance is supported.
Support for OOP in C# (continued)
- Dynamic binding is possible by marking methods virtual.
- Derived class methods can override virtual parent methods (override keyword).
- Abstract classes have abstract methods.
- All C# classes are ultimately derived from a single class: Object.
Support for OOP in C# (continued)
- Nested classes resemble Java's static nested classes.
- C# nested classes cannot behave like Java's non-static nested classes.
Support for OOP in C# (continued)
- Evaluation:
- Newer C-based OO language.
- Differences between it and Java are minor.
Support for OOP in Ruby
- Everything is an object in Ruby.
- Computations occur via message passing.
- Class definitions are executable and allow secondary definitions to expand existing classes; method definitions are executable.
- All variables are type-less references.
- Access control is different for data and methods.
- Methods can be public, private, or protected.
- Access is checked at runtime.
- Getters and setters declared using shortcuts.
Support for OOP in Ruby (continued)
- Access to inherited methods can differ from parent classes.
- Subclasses aren't necessarily subtypes.
- All variables are typeless and polymorphic.
- Doesn't support abstract classes and does not support multiple inheritance.
- Access controls are weaker than in other languages.
Implementing OO Constructs
- Interesting issues include storage structures for instance variables and dynamic binding of messages to methods.
Instance Data Storage
- Class instance records (CIRs) store an object's state.
- CIRs are static (built at compile time).
- Subclass CIRs inherit parent variables.
- Accessing instance variables from CIRs is efficient because access is done as in records.
Dynamic Binding of Methods Calls
- Statically bound methods in a class aren't contained in the CIR.
- Methods dynamically bound to CIRs are connected to the code using a pointer.
- CIR storage structures are sometimes called virtual method tables (vtable).
- Method calls can be offsets from the beginning of the vtable.
Reflection
- Programming languages with reflection permit runtime access to object types and structure and ability to modify behavior.
- Types/structure of programs are called metadata.
- Examining program metadata is introspection.
- Interceding program execution is intercession.
Reflection (continued)
- Programs use reflection for software tools (e.g., class browsers).
- Visual IDEs use type information.
- Debuggers examine private fields and methods.
- Test systems use reflection to know class methods.
Reflection in Java
- Java provides limited reflection support from java.lang.Class.
- Java runtime instantiates a Class object for each program object.
- Class methods, getMethods, getDeclaredMethods/Method find public/all methods.
Reflection in C#
- .NET languages place intermediate code in assemblies along with program metadata.
- System.Type is the reflection namespace; getType() is used instead of getClass().
Downsides of Reflection
- Reflection has performance implications.
- Reflection exposes private fields and methods.
- Reflection can negate early type checking.
- Some code might not run under a security manager (making it non-portable).
Summary
- OOP involves ADTs, inheritance, and dynamic binding.
- Design issues include exclusivity of objects and subclasses.
- Smalltalk is purely object-oriented, and C++ has a mixed type system.
- Java and C# are primarily object-oriented, and Ruby is purely object-oriented.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.