Object-Oriented Programming Flashcards
What are the major programming paradigms?
Imperative
–uses statements to change a program’s state
Declarative
–describes the desired result, system figures out how to achieve it
What are the tyes of imperative programming? (3)
- Procedural
- OOP
- Recursive Programming
What are the tyes of declarative programming? (3)
- Functional Programming
- Logic Programming
- Constraint Programming
What type of programming does Python use?
What about java?
-tends toward functional, but supports procedural and object-oriented
-primarily object-oriented, but added constructs to allow
functional programming
Describe the features of objects (3, one depends on the language)
An object:
–collects together related data (“fields”, “attributes”)
–collects together subroutines to work on that data (“methods”, “member functions”, etc.)
–may (depending on the language) allow hiding the data members and/or function members, restricting access to them to its subroutines only
What are the features of OOP languages? (5)
Encapsulation
– related data and procedures are kept together, and data or even
procedures may be hidden from outside access
Classes (definition of data/procedures)
– class variables (belong to the class as a whole, e.g. “static” in Java)
Objects (instances of a Class)
– instance variables (belong to a particular object)
Composition
– objects can contain other objects as members
Inheritance or Delegation
What is not a defining feature of OOP but almost always present?
Inheritance
What is inheritance?
means that a subclass can use subroutines or data members defined in an ancestor class
What is delegation?
means that a member of an object (“receiver”) is evaluated in the context of some other object (“sender”)
– can be done by passing the sender to the receiver as a parameter
Describe polymorphism? What allows it?
Polymorphism
– Inheritance allows Polymorphism
– a single function call in the source code can invoke different functions at runtime depending on the type of the object
– implemented by having a table of function pointers associated withevery object (one table per class)
What is SOLID?
Acronym for five principles of Object-Oriented Design
– SRP: Single Responsibility Principle
– OCP: Open/Closed Principle
– LSP: Liskov Substitution Principle
– ISP: Interface Segregation Principle
– DIP: Dependency Inversion Principle
What is a singleton?
A class which never has more than a single object instantiated
How do you implement a singleton? (2)
- hiding the class constructor –
- providing a static function that returns the sole instanc
What’s an adapter? (1)
Convert the interface of a class to look like another class’s interface
- What’s an iterator? (1)
- How is it implemented?
- allows traversal of a container object and accessing the container’s elements
- typically implemented as a class with functions such as init(), next(), and getItem()