3. Polymorphism Flashcards

1
Q

What does polymorphism mean?

A

Polymorphism means that you can have multiple classes that can be used interchangeably, even though each class implements the same properties or methods in different ways.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is one of the ways that we can use Polymorphism?

A

Creating interfaces is one of the ways we can use polymorphism.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an interface?

A

An interface is a contract that allows us to know that particular public methods and properties will always be available on a class that implements the interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the default and the only access modifier an interface property or method can have?

A

Public. They cannot be set to anything else.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you add business logic to interfaces?

A

You do not. You only add the API calls themselves.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does a class implement an interface?

A

Exactly the same way that it extends a base class to it. By using the interface’s name after columns next to the class’s own name. Though, it must also implement the properties and methods defined in the interface.

eg. class ConcreteClass : BaseClass, IMyInterface { ... }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you test for whether an object’s class implements a certain interface?

A

By casting the object as the interface using the as keyword. This will return null if the class doesn’t implement the interface and the same object if it does.

eg. object as IMyInterface; // return true if it does, false if not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is composition?

A

Composition is extracting common business logic between classes into a separate class and reuse that class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does composition allow us to do?

A

Composition allows us to share the same code in multiple places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the sealed keyword?

A

It is a modifier that prevents a given class from being inherited by others.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly