OOP Review

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

Types of Polymorphism

1. Overriding 2. Overloading

BLANK is the emphasis on ideas, qualities and properties rather than on the particulars.

Abstraction

The term API stands for BLANK

Application Programming Interface

LSP

Liskov Substitution Principle: Derived classes must be substitutable for their base classes.

Can an interface be instantiated?

NO

Overriding

Run-time polymorphism is determined at run-time based on the type of the object

SRP

Single Responsibility Principle: A class should have ONLY ONE reason to change

Method signature

The name and list of parameters of a method

When is an interface useful?

When implementation must be interchangeable

How to identify classes

1. Identify a full list of operations of the system and granular level use cases 2. Group each function to form classes; should support reusability and increase expandability/maintainability of the system. Identify the modules first, then dig deeper to find classes

Benefits of Encapsulation

1. You can make changes to a class without breaking other code using that class. 2. You can handle situations where the class is being used improperly in such a way that the code doesn't fail.

What Is a Package?

A package is a namespace for organizing classes and interfaces in a logical manner. It makes large software projects easier to manage.

What is a package?

A package is a namespace that organizes a set of related classes and interfaces.

Specialization

An "is-a" relationship between two classes, represented by inheritance. Example: Dog "is-a" mammal

Object

An instance of a class or type of data.

Difference between an interface and a class?

An interface cannot be instantiated, and an interface is empty; it contains declarations of properties/methods but no implementations; a class must contain implementations.

An abstract class can implement how many interfaces?

As many as you want

Techniques classes use to link with each other

Association Aggregation Composition

Why must the superclass' code be carefully documented?

Because that code is not physically in the subclass.

Class

Blueprint/prototype from which objects are created

Code re-use

Complex objects only need to be coded once; you can use classes that have already been created by others.

DIP

Dependency Inversion Principle: Depend on abstractions, not on concretions.

Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data BLANK

Encapsulation

Major Principles of Object-Oriented Programming

Encapsulation Abstraction Inheritance Polymorphism

Example of Composition

Example of Composition Courses exist only within their department; therefore if a department no longer exists, neither do its courses.

Encapsulation

Hiding the internal state of an object (usually a private variable) and requiring all interaction to be performed through an object's accessor and mutator methods. ( or getter and setter methods). Example: In a Bicycle class, method changeGear() could be implemented so as to only accept values between 1 and 6

Pluggability/Debugging Ease

If an object is causing problems, you can easily remove it and put something else in its place. Example: replace a bolt that is broken, not the whole machine.

What is encapsulation?

It describes the idea of bundling data and methods that work on that data within one unit, e.g., a class in Java. This concept is also often used to hide the internal representation, or state, of an object from the outside.

What is OOP?

It stands for Object Oriented Programming. Object-Oriented Programming (OOP) instead of the old procedural programming languages methods (That creates the spaghetti code problem). Everything in OOP is grouped as self sustainable "objects". This modular method promotes code reusability and is easier to debug.

Can you override a method in a subclass that has a different signature in its superclass?

NO, in order to override the method must have the same signature in both the subclass and the base (super) class.

Can Abstract Classes be instantiated?

No

Parameterization

One or more parts of an entity are replaced with a name that is new to the entity (a parameter)

OCP

Open Closed Principle: You should be able to extend any classes' behaviors without modifying the class.

When a class inherits from an abstract class, you MAY:

override virtual methods/properties

A namespace that organizes classes and interfaces by functionality is called a BLANK

package

Mutator

public methods used to modify the state of an object while hiding the implementation of the method

Generalization

replaces multiple entities which perform similar functions with a single construct.

Behavior

set of activities performed by an object

Modularity?

source code for an object can be written/maintained independently of source code for other objects. objects can be easily passed around the system once they've been created.

An accessor is any public method that gives information about the BLANK of an object

state

5 Principles of designing a Class

1. SRP (Single Responsibility Principle) 2. OCP (Open Closed Principle) 3. LSP (Liskov Substitution Principle) 4. DIP (Dependency Inversion Principle) 5. ISP (Interface Segregation Principle)

What is the only type of class that does NOT have to define all methods in an interface that it is implementing?

Abstract class; it doesn't matter because it can't be instantiated, BUT those methods that are not defined in the abstract class MUST be defined by its subclasses

array vs arraylist?

Array is a fixed length data structure whereas ArrayList is a variable length Collection class.

Information-Hiding

By interacting only with object's methods, details of internal implementation stay secret from outside world.

Overloading

Compile-time polymorphism: the compiler determines which method will be executed based on which parameters were supplied. Multiple methods with different signatures (different parameters).

How does abstraction manage complexity?

Decomposes complex systems into smaller components; You know what behavior to expect from the object even before it is fully implemented, so it won't have a negative impact on later coding if it isn't completely finished.

BLANK places emphasis on similarities between objects

Generalization

What is inheritance?

Inheritance enables new objects to take on the properties of existing objects.

ISP

Interface Segregation Principle: Make fine grained interfaces that are client specific.

What is a benefit of using packages?

It allows developers to focus on the design of an application and NOT the technical stuff that makes it work.

Should the methods in an interface be public or private?

MUST be public

Benefits of Objects?

Modularity Information-Hiding Code re-use Pluggability and debugging ease

What is multiple inheritance? Why is it bad?

Multiple Inheritance is a feature of object oriented concept, where a class can inherit properties of more than one parent class. The problem occurs when there exist methods with same signature in both the super classes and subclass. On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority.

Does Java allow multiple inheritance?

No, Java supports single and multi level inheritance but not multiple inheritance.

How many superclasses can a subclass have?

ONLY ONE

What is an object?

Object refers to a particular instance of a class, where the object can be a combination of variables, functions, and data structures.

What is OOP?

Object-Oriented Programming is a programming style related to concepts of Class, Objects, and various other concepts like Inheritance, Abstraction, Encapsulation, and Polymorphism.

An Abstract class can ONLY be used as a ...?

Superclass

What is abstraction?

The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface).

What is the use of a public constructor in an abstract class?

There is none, because an abstract class cannot be instantiated.

Primary goal of software architecture

To define the non-functional requirements of a system and define the environment;

What is inheritance?

When subclasses can inherit states/behaviors of superclasses

Can interfaces inherit other interfaces?

Yes

What is a class?

a class is a blueprint for creating objects.

class library?

a set of packages

Method Overriding

allows a subclass to change the implementation of a method already provided by a superclass; both classes MUST use the same signature for the method to override.

How to use the changeGear() method on a Bicycle object bike1?

bike1.changeGear();

How does generalization manage complexity?

collects individuals into groups and provides a representative which is used to specify an individual of the group.

Method Overloading

defining several methods that have the same name but different signatures.

What is Abstraction?

development of classes/objects/types in terms of interfaces and functionality, instead of implementation details; development of a software object to represent a real-world object.

A software object's state is stored in BLANK

fields

Association

general term that defines the relationship between two classes; NO OWNERSHIP

Main benefit of abstraction?

manages complexity

Accessor

method used to ask an object about itself

A software object's behavior is exposed through BLANK

methods (functions)

Operator Overloading

operators have different behaviors depending on the types of its arguments Example: with strings, + concatenates, but with ints, + adds?

When a class inherits from an abstract class, you MUST:

override all of its methods/properties that are declared to be abstract.

Common behavior can be defined in a BLANK and inherited into a BLANK using the BLANK keyword

superclass, subclass, extends

What do the Java API's packages represent? Give examples.

tasks for general purpose programming: String, File, Socket, some for developing GUIs.

Example of Aggregation

teachers belong to multiple departments, so if a department no longer exists, the teacher still does.

Programming languages provide generalization through:

variables, parameterization, generics, and polymorphism

Aggregation

weak ownership between two classes; the "owned" class can exist without its owner

Can an interface contain properties?

yes; must be public/abstract

A blueprint for a software object is called a BLANK

class

A collection of methods with no implementation is called an BLANK

interface

Should an accessor be public or private?

must be public

Superclass

only contain info common to all of its subclasses

What is polymorphism? What are the types of polymorphism?

polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. Method overloading is an example of static polymorphism, while method overriding is an example of dynamic polymorphism.

Constructor in Java

Constructors are used to initialize the object's state. Like methods, a constructor also contains collection of statements(i.e. instructions) that are executed at time of Object creation.

A BLANK separates implementation and defines structure.

interface

How many subclasses can inherit from the same superclass?

Infinitely many

What is a constructor?

A constructor is a special method of a class or structure in object-oriented programming that initializes an object of that type.

What is the only type of class that does NOT have to define all methods in an interface that it is implementing?

Abstract class; it doesn't matter because it can't be instantiated, BUT those methods that are not defined in the abstract class MUST be defined by its subclasses.

What is an abstract class?

Abstract classes, unlike interfaces, are classes. There are more expensive to use because there is a lookup to do when you inherit from them. Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them.

Primary means of managing complexity in large programs.

Abstraction

What is abstraction?

Abstraction is one of the key concepts of object-oriented programming (OOP) languages. Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity.

Difference between an interface and an ABSTRACT class?

An interface contains only the constants/methods that a class. An abstract class CAN contain fully-implemented methods and properties other than constants. Methods of interfaces must be defined as public, whereas methods in abstract classes can have any visibility. A subclass can only extend one superclass, whereas interfaces can implement multiple other interfaces. A subclass can define abstract methods with the same or less restrictive visibility, whereas when implementing an interface the methods must have the exact same visibility.

Difference between an interface and an ABSTRACT class?

An interface contains the constants/methods that a class implementing it should have, but does NOT contain the bodies of methods or values other than constants. An abstract class CAN contain fully-implemented methods and properties other than constants. Methods of interfaces must be defined as public, whereas methods in abstract classes can have any visibility. A subclass can only extend one superclass, whereas interfaces can implement multiple other interfaces. A subclass can define abstract methods with the same or less restrictive visibility, whereas when implementing an interface the methods must have the exact same visibility.

What Is an Interface?

An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class). For example, say we have a car class and a scooter class and a truck class. Each of these three classes should have a start_engine() action.

What is interface?

An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class). For example, say we have a car class and a scooter class and a truck class. Each of these three classes should have a start_engine() action.

What is interface?

An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class). For example, say we have a car class and a truck class. Each of these two classes should have a start_engine() action.

Benefits of software architecture

Controls Complexity Enforces best practices Consistency/uniformity Increases predictability Enables re-use

What does a class consist of?

Name, attributes and operations (state and behavior)

Real-world objects contain BLANK and BLANK.

State, behavior

Composition

Strong type of association between two classes with full ownership.

What is the main benefit of using inheritance?

The subclass contains all of the methods/fields of the superclass, but the subclass' code focuses on the unique aspects, making code simpler and easier to read.


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

AFJROTC // Chapter 6 Lesson 2 Preparing Your Résumé Test

View Set

Fundamental Chapter 37: Urinary Elimination

View Set

Anatomy and Physiology I Final Exam

View Set

HESI Module 1 Exam-Developmental Stages and Transitions

View Set

QA interview Questions, **QA-Interview**

View Set

Basisfragen (Frage 1 bis Frage 72)

View Set

Module 24: Storing & Retrieving Memories

View Set