week03 Abstraction&relationaships&testing Flashcards
What is OOP?
OOP is a style of programming that models the real world. It uses objects and classes to create reusable code.
True or false?
“OOP only uses Encapsulation and Inheritance as its main techniques”
False. OOP uses Modularity, Abstraction, Encapsulation, Inheritance, and Polymorphism.
polymorphism: ある1つのメソッドを呼び出しに対して、オブジェクト毎に異なる機能や動作を示すこと。多態性。
What does modularity mean in OOP?
Modularity refers to dividing a program into separate modules that can be developed and tested independently.
Why is encapsulation is important in OOP?
Encapsulation protects object integrity by hiding its internal state and requiring all interaction to be performed through its methods.
What is inheritance in OOP?
Inheritance allows a new class to adopt the properties and methods an existing class.
True or false?
“Polymorphism in OOP means that a single function can work in many different ways”
True. Polymorphism allows methods to do different things based on the object they are acting upon
What are the benefits of using OOP?
OOP makes code more flexible, easier to maintain, and resusable, leading to efficient and effective programming practices.
What does coupling in mean in Java?
Coupling is how closely different parts of a program work together. We want less couling to make changes easier.
What is cohesion in Java?
Cohesion is when parts of a program that belong together are kept together. High cohesion makes a program more strong and organized.
True or false?
“We want maximum cohesion in our Java programs”
True.
Why maximum independence important in java?
Independence means each part can work on its own. This makes the progra more flexible and easier to fix.
What is composition in OOP?
Composition is when a class includes objects from other classes as part of its structure. It’s ‘has-a’ relationship.
True or false?
“A unidirectional association means both classes know about each other”
False. In a unidirectional association, only one class contains a reference to the other.
True or false?
“In a bidirectional association, both objects contain references to one another.”
True.
What is the Law of Demeter?
It is a rule for writing software. It says objects should only talk to close friends, not strangers. This means a class should only know limited things about other classes. It should talk only to its direct friends.
What does making a parameter final do?
It does not let you change the parameter’s value inside the method.
How to write symbolic constants in Java?
Use final
keyword. Write class-level constants in ALL_CAPS and local constatnts in camelCase.
True or false?
“Assign a value to a symbolic constant when it’s declared.”
True. A symbolic constant should get its value immediately when declared.
When to assign value to a final instance variable?
Assign during object construction if it’s meant to only set once.
True or false?
“Class-level constants should be static and final for memory efficiency”
True. Static means it’s class-wide, final means it’s unchangeable. It’s memory efficient.