OOD Part 3
40 Questions
2 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following is a core principle of Object-Oriented Programming (OOP)?

  • Functional composition
  • Modular programming
  • Encapsulation (correct)
  • Procedural decomposition

In object-oriented design, what is the primary purpose of abstraction?

  • To reduce the amount of code written
  • To directly access and manipulate internal data of objects
  • To increase the complexity of the system
  • To hide complex implementation details and expose only essential information (correct)

Which concept allows a class to inherit properties and methods from another class?

  • Polymorphism
  • Abstraction
  • Inheritance (correct)
  • Encapsulation

What is the term for the ability of different classes to respond to the same method call in their own way?

<p>Polymorphism (A)</p> Signup and view all the answers

Which languages support operator overloading?

<p>C++ and C# (C)</p> Signup and view all the answers

In languages that support it, what is the primary reason to avoid excessive operator overloading?

<p>It makes code harder to read and maintain. (C)</p> Signup and view all the answers

Which of the following access modifiers provides the most restrictive access?

<p>Private (C)</p> Signup and view all the answers

If a class member is declared as 'protected', where can it be accessed?

<p>Within the class itself, and by derived classes. (B)</p> Signup and view all the answers

What does the sealed keyword prevent in C#?

<p>Prevents the class from being inherited. (D)</p> Signup and view all the answers

What is the significance of the virtual keyword in C#?

<p>It allows a method to be overridden in a derived class. (D)</p> Signup and view all the answers

In the context of class methods, what is method overriding?

<p>Providing a specific implementation for a virtual method in a derived class. (C)</p> Signup and view all the answers

What condition must be met for method overloading to occur?

<p>The methods must have the same name but different parameters. (C)</p> Signup and view all the answers

Which of the following statements best describes an interface in object-oriented programming?

<p>A definition for a group of related functionalities that a class must implement. (A)</p> Signup and view all the answers

How does an interface differ from an abstract class?

<p>A class can implement multiple interfaces but can only inherit from one abstract class. (C)</p> Signup and view all the answers

Why are interfaces considered more flexible compared to inheritance in some scenarios?

<p>Because a class can implement multiple interfaces, allowing it to adhere to several contracts. (C)</p> Signup and view all the answers

What is the primary purpose of generic classes?

<p>To encapsulate operations that are not specific to a particular data type. (A)</p> Signup and view all the answers

In Java, what is the role of angle brackets <> when using ArrayList?

<p>They indicate the variable type stored in the ArrayList. (B)</p> Signup and view all the answers

Which of the following is a key concern of Object-Oriented Design (OOD)?

<p>Reusing as much code as possible and limiting redundancy. (D)</p> Signup and view all the answers

What is the purpose of constructors in object-oriented programming?

<p>To initialize the state of an object when it is created. (C)</p> Signup and view all the answers

In C#, what are destructors also known as?

<p>Finalizers (A)</p> Signup and view all the answers

When is a destructor typically called?

<p>Automatically by the garbage collector when an object is no longer in use. (C)</p> Signup and view all the answers

If memory is no longer needed during runtime, where is it cleared from?

<p>The heap (D)</p> Signup and view all the answers

Which component is responsible for automatically freeing up memory that is no longer being used by a program?

<p>The garbage collector (C)</p> Signup and view all the answers

Why is it important to free memory that is no longer being used by a program?

<p>To prevent memory leaks and ensure efficient resource utilization. (A)</p> Signup and view all the answers

What is the correct format to define a destructor for ClassName?

<p>~ClassName() (D)</p> Signup and view all the answers

What is a 'getter' primarily used for in the context of object properties?

<p>To retrieve the value of a property. (B)</p> Signup and view all the answers

What happens when a class implements an interface?

<p>The class must provide implementations for all members declared in the interface. (C)</p> Signup and view all the answers

Which of the following is true about 'internal' access modifier?

<p>Accessible within the same assembly (D)</p> Signup and view all the answers

What happens if a derived class does not override a virtual method in a base class?

<p>The base class's implementation of the method is used. (C)</p> Signup and view all the answers

Which memory location are local variables stored?

<p>Stack (D)</p> Signup and view all the answers

Which memory location are dynamic variables stored?

<p>Heap (D)</p> Signup and view all the answers

What is a base class also known as?

<p>Parent class (A)</p> Signup and view all the answers

What is a derived class also known as?

<p>Child class (A)</p> Signup and view all the answers

What term describes containing information in an object, exposing selected information?

<p>Encapsulation (B)</p> Signup and view all the answers

What technique can be used to construct complex systems with primitive objects and primitive data?

<p>Means of combination (B)</p> Signup and view all the answers

What can higher order functions be used for with Object oriented design?

<p>Capturing common patterns (C)</p> Signup and view all the answers

Which of the following is an Object Oriented language?

<p>Rust (A)</p> Signup and view all the answers

Which of the following can be overloaded in C#?

<p>Operators (D)</p> Signup and view all the answers

What is the closest mechanism to operator overloading in Java?

<p>toString() (D)</p> Signup and view all the answers

What are the downsides of using operator overloading?

<p>It can make code harder to maintain (D)</p> Signup and view all the answers

Flashcards

Object-Oriented Design

A design paradigm centered around 'objects' which contain data and code to manipulate that data.

Github

A place to store and manage your code

Encapsulation

Containing information within an object and exposing only selected information.

Abstraction

Exposing only high-level public methods for accessing an object.

Signup and view all the flashcards

Inheritance

Child classes inheriting data and behaviors from the parent class.

Signup and view all the flashcards

Polymorphism

Many methods performing the same task.

Signup and view all the flashcards

Computer Science

A discipline focused on building abstractions to manage complexity and produce correct, performant code.

Signup and view all the flashcards

Operator Overloading

A feature in some object-oriented languages where operators (+, -, etc.) can have different meanings based on their operands.

Signup and view all the flashcards

Operator Overloading

A feature that is very common in programming langauges such as C++, C#, Python

Signup and view all the flashcards

'operator' keyword

In C#, special methods are used to overload operators.

Signup and view all the flashcards

Operator Overloading in Java

Not supported, except toString() can be remotely linked to it.

Signup and view all the flashcards

Drawback of Operator Overloading

Can make code harder to read.

Signup and view all the flashcards

Inheritance

A mechanism where a class (child) acquires properties and methods of another class (parent).

Signup and view all the flashcards

Static Members

Variables or methods belonging to the class itself, not instances.

Signup and view all the flashcards

Instance Members

Variables or methods that are unique to each object of a class.

Signup and view all the flashcards

Access Modifiers

Keywords that control the visibility of class members (public, private, protected).

Signup and view all the flashcards

Public

Visible everywhere.

Signup and view all the flashcards

Private

Visible only within the class it is defined.

Signup and view all the flashcards

Protected

Visible within the class and its subclasses.

Signup and view all the flashcards

Sealed

Defines something that cannot be inherited.

Signup and view all the flashcards

Internal

Visible only within the same assembly.

Signup and view all the flashcards

Virtual

Members can be overridden in derived classes.

Signup and view all the flashcards

Base/Parent

The class you inherit from

Signup and view all the flashcards

Derived/Child

The class that inherits from the parent

Signup and view all the flashcards

Overriding

Used in derived class to provide a specific implementation of a method that is already defined in its base class.

Signup and view all the flashcards

Overloading

Multiple methods with the same name but different parameters.

Signup and view all the flashcards

Interface

A contract that defines a set of methods a class must implement.

Signup and view all the flashcards

Abstract Class

Can have variables

Signup and view all the flashcards

Interfaces

Cannot have variables

Signup and view all the flashcards

Abstract Class

Can only inherit one class

Signup and view all the flashcards

Interfaces

Can implement multiple interfaces

Signup and view all the flashcards

Generic Classes

Parameters that define type in a class.

Signup and view all the flashcards

Generic Classes

Encapsulate operations are not specific to a particular data type

Signup and view all the flashcards

OOD Concerns

Focus on reusing code and reduce redundancy in design.

Signup and view all the flashcards

Properties

Functions for data and control access

Signup and view all the flashcards

Properties

Are different from variables of a class

Signup and view all the flashcards

Getters

Functions that retrieve the values of properties.

Signup and view all the flashcards

Setters

Functions that set (modify) the values of properties.

Signup and view all the flashcards

Constructors

Methods to construct new objects.

Signup and view all the flashcards

Destructors

Methods to clean up or perform final actions before an object is destroyed.

Signup and view all the flashcards

Stack

Temporary space allocation

Signup and view all the flashcards

Heap

Long term allocation of space

Signup and view all the flashcards

Garbage Collector

An automatic process that reclaims memory no longer in use by the program.

Signup and view all the flashcards

Study Notes

Object Oriented Design

  • Creating a GitHub account is typically the first step when working with a team in this design paradigm.
  • Check your email for invites to the correct organization and make sure everyone on the team gets added.
  • Permissions are handled in GitHub teams.

Techniques for Managing Complexity

  • Black box abstraction, primitive objects, procedures, and primitive data are used to manage complexity.
  • Combining procedures and data types serves as a means of organizing code.
  • Abstraction encapsulates procedure definitions and implements data structures.
  • Common patterns are captured using higher-order functions and treating data as procedures, and procedures as data.

Object Oriented Programming (OOP)

  • The four pillars of OOP are encapsulation abstraction, inheritance, and polymorphism.
  • Encapsulation contains information in an object, exposing only selected information.
  • Abstraction exposes high-level public methods for accessing an object.
  • Inheritance allows child classes to inherit both data and behaviors from the parent class.
  • Polymorphism allows many methods to perform the same task.

Building Abstractions in Computer Science

  • Computer Science is a discipline that builds abstractions to manage complexity.
  • The goal is to write correct and high-performing code.

Gameplan: OOP Languages and Design Patterns

  • Object Oriented Languages
    • C#, C++, Java, TypeScript/JavaScript, Python, and Rust are object-oriented languages.
  • Operator Overloading
    • Operator overloading is present in languages like C++, C#, and Python.
    • Some languages, like Java and JavaScript/TypeScript, do not support operator overloading.
  • C# Operator Overloading
  • Java: toString Method
    • The toString method in Java can be remotely linked to operator overloading.
  • Python Methods
    • Python uses _str() and _add() methods for operator overloading.
  • Drawbacks of Operator Overloading
    • Using it can make code harder to read and maintain, as it might obscure functionality compared to explicit functions.

Inheritance

  • Before delving deep into inheritance there are some concepts that should be fully understood
  • These are:
    • Static versus Instance
    • Why inherit
    • Access Modifiers
  • Access Modifiers
    • Public access modifiers
    • Private access modifiers
    • Protected access modifiers
    • Abstract access modifiers
    • C# modifiers
    • Sealed Modifiers
    • Internal Modifiers
    • Virtual Modifiers
  • Terminology
    • Base == Parent
    • Derived == Child
  • Morale of the story
    • People will kill end themselves if given too many choices

Interfaces: What They Are and How They Differ from Abstract Classes

  • An interface contains definitions for a group of related functionalities that a non-abstract class or struct must implement.
  • Interfaces may define static methods with mandatory implementations and default implementations for members.
  • They cannot declare instance data like fields or auto-implemented properties.
  • An in-depth reference can be found at: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces
  • Abstract Class vs Interface:
    • Abstract Classes can have variables and can only inherit one class, but can have virtual functions.
    • Interfaces can implement multiple interfaces but can only have abstract-like members.
  • Examples
    • interface IImage { void Save(); void Load(); }
    • interface IEquitable<T> { bool Equals(T obj); }
    • public interface IComparable { int CompareTo(object obj); }

Generic Classes: Flexibility Compared to Inheritance

  • OOD(Object-Oriented Design) aims to reuse as much code as possible and limits redundancies.
  • Techniques seen include:
    • Using functions
    • Defining variables and constants
  • Generic classes encapsulate operations that are not specific to a particular data type.
  • The most common use for generic classes is with collections like linked lists, hash tables, stacks, queues, and trees.
  • Java uses ArrayList<> to store variable types
  • Let's Boil Down the List
    • Add / Concat
    • Remove
    • Index
    • Size
    • Head/Tail
    • Sort: a way to compare
    • Search: a way to compare
    • Any other?

Dependency Injection

Other Notes

  • Properties
    • Properties differ from variables
    • Usually public access
    • Customize access with getters and setters
  • Getters and Setters
    • Functions for properties
    • Accessors have getters and setters
    • Can also be customized or use default
  • Constructors
    • Needed to create objects
    • Can be overloaded with multiple methods
    • Always public
    • Instance variables
  • Destructors
    • C# calls them Finalizers
    • Called when the object is destroyed by the garbage collector
    • Format: "~ClassName()"

Low Level Memory Management

  • Memory and data are kept in one of 2 locations
    • Stack
    • Local Variables
    • Graphics look like Pancakes
    • Heap
    • Dynamic
    • Graphics look like trees
  • Why Free Memory?
    • Only limited amounts of space are available in OS
    • The OS defines limited zone of operation
  • Garbage Collection
    • Garbage Collectors clean up old data
    • They are Done automatically by most modern languages to clear memory
    • Clears items from the heap that no longer have anything else pointing to them

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser