Chapter 2 - Advanced Principles Flashcards
Difference of Object vs. value
value: abstract value, no lifecycle, no side effects, immutable (unveränderbar) state (integer, float, character), Object: describes a phenomenon in a problem domain, lifecycle (created, mutation, deletion), can e shared
define “type”
abstract description of properties of a set of objects
define “class”
implementation of a type
What are the pre- and postconditions of the Liskov substitution principle?
preconditions must not be widened by a subtype, postconditions must not be narrowed (verschmälert) by a subtype
explain subclass
T’ is a subclass of T if T’ is derived form T (Implementation inheritance)
explain subtype
T’ is a subtype of T if T-objects can be replaced by T’-objects (subtype is more strict than subclass)
what is covariance and contravariance?
Covariance: type of a method parameter is narrowed (eingeschränkt) in a subclass, Contravariance: type of a method parameter is widened (ausgeweitet) in a subclass. most oo-languages only support contravariance
What types are there for Inheritance?
Specialization: derived concrete subclass from concrete base class / Specification: concrete subclass implements abstract base class / Restriction: subclass restricts the base class interface / Combination: multiple inheritance / Construction: Implementation inheritance
How can you restrict the Inheritance Interface?
in order to prevent method overriding, you can use the keyword final
Explain Inheritance vs. Composition
inheritance: is-a relationship, composition is has-a relationship
What is the problem with Inheritance?
it violates encapsulation
how does a Java interface work?
it declares only abstract methods
how does a Java abstract class work?
it defines common and structural functional properties
Explain Factorization
Sachverhalt nur an einer einzigen Stelle festhalten, eliminates duplicate code
what is information hiding?
minimal coupling between classes, open-closed principle: class should be open for extensions but closed for modifications