Basics of OOP Flashcards
Object-oriented programming is
a paradigm based on the con-
cept of wrapping pieces of data, and behavior related to that
data, into special bundles called objects, which are construct-
ed from a set of “blueprints”, defined by a programmer, called
classes.
Data stored inside the object’s fields is often referenced
as ____, and all the object’s methods define its _____.
Data stored inside the object’s fields is often referenced
as state, and all the object’s methods define its behavior.
A parent class, is called a
____. Its children are ____.
A parent class, like the one we’ve just defined, is called a
superclass. Its children are subclasses.
Subclasses inherit ____
and ___ from their parent, defining only ___ or ____ that differ
Subclasses inherit state
and behavior from their parent, defining only attributes or
behaviors that differ
Assumingthatwehavearelatedbusinessrequirement,wecan
go even further and extract a more general class for all liv-
ing Organisms which will become a superclass for Animals
and Plants . Such a pyramid of classes is a
hierarchy. In such
a hierarchy, the Cat class inherits everything from both the
Animal and Organism classes.
What can subclasses override from parent classes?
Subclasses can override the behavior of methods they inherit from parent classes.
How can subclasses change the behavior of inherited methods?
Subclasses can either completely replace the default behavior or enhance it with extra features.
Can subclasses enhance the default behavior of inherited methods?
es, they can enhance the default behavior with some extra stuff.
Difference between Abstract Classes and Interfaces?
Abstract classes can have both abstract and concrete methods; whereas, interfaces can only have abstract methods.
An interface is a contract that specifies a set of methods that a class that is implementing must implement.
Can Association have many-to-many relationship?
In can be represented as one-to-one, one-to-many, or many-to-many (aka cardinality).
Code reuse
Using design patterns is one way to increase flexibility of software components and make them easier to reuse. However, this sometimes comes at the price of making the components
more complicated.
Encapsulate What Varies
Identify the aspects of your application that vary and separate them from what stays the same.
What should all products follow in the Factory Method pattern?
All products should follow the same interface, declaring methods that make sense for every product.
What should the return type of the factory method match?
The return type of the factory method should match the common product interface.
What should you replace product constructor references with in the creator’s code?
Replace them with calls to the factory method, extracting the product creation code into the factory method.