SWE Interview - Set 5 Flashcards
Describe an example of Polymophism using:
- Animal Class
- Dog Class
- Cat Class
- Method: makeSound()
Animal class has makeSound(); Dog and Cat extend Animal, overriding makeSound() with specific sounds, allowing polymorphic use of makeSound(). Despite declaring an instance of dog
and cat
as Animal type, they can hold instances of Dog
and Cat
, respectively.
What is an example of a connascent code? (with Spring boot app in mind.)
A UserService relies on the UserRepository interface rather than a concrete implementation. This reduces connascence because UserService isn’t tightly coupled to a specific implementation of the repository, promoting flexibility and easier maintenance.
What is Low coupling?
Low coupling signifies that modules are relatively independent of each other.
What is a fundamental principle in software design to promote more flexible, maintainable, and scalable systems?
Aiming for low coupling and high cohesion for more flexible, maintainable, and scalable systems.
What design principles aid in reducing direct dependencies between modules to achieve low coupling in software development?
Dependency Injection, Interfaces, and Abstraction facilitate the creation of modules interacting through well-defined interfaces, reducing direct dependencies and promoting flexibility.
What are the types of polymorphism?
- Runtime Polymorphism
- Compile Time Polymorphism
Operator overloading
Operator overloading refers to the ability to define multiple behaviors for a specific operator based on the context of its operands. It allows customizing how operators like +, -, *, etc., work with user-defined objects, enhancing code clarity and flexibility by enabling intuitive operations on custom types.Not supported in Java
What is Function/Method overloading? Describe an example.
When multiple functions with the same name but different parameters are defined in a class. The appropriate function is chosen during the compile time based on the arguments provided.An example of Compile-Time Polymorphism
What are other design patterns of IoC?
- Service Locator Pattern
- Factory Pattern
- Event-based IoC
Polymorphism
Ability to present one interface for multiple data types, allowing objects of different classes to be treated as objects of a common superclass.
Inheritance
Mechanism where a new class inherits properties and behavior from an existing class, fostering code reuse and establishing a hierarchical relationship.
Encapsulation
Concept of bundling data and methods within a class, restricting access to the internal state of an object and promoting data integrity.