Software Engineer concepts Flashcards
Encapsulation in OOP
- Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data into a single unit called a class. It also involves restricting access to some components, protecting the integrity of the object’s data by using access modifiers such as private, public, and protected.
- Example: A Car class with private data like speed and public methods like accelerate() and brake().
Abstraction in OOP
- Abstraction hides the complex implementation details of a system and shows only the essential features to the user. The idea is to reduce complexity and allow the programmer to focus on interactions at a high level.
- Example: You use a method startEngine() in a Car class without needing to know the internal workings of how the engine starts.
Inheritance in OOP
- Inheritance allows one class (child or subclass) to inherit properties and methods from another class (parent or superclass). This promotes code reuse and establishes a natural hierarchy between classes.
- Example: A Sedan class can inherit from a general Car class, thus inheriting properties like speed and methods like drive().
Polymorphism in OOP
- Polymorphism means “many forms” and allows objects of different classes to be treated as objects of a common superclass. There are two types of polymorphism:
- Compile-time (method overloading): Multiple methods can have the same name but different parameters.
- Run-time (method overriding): A subclass can provide its own implementation of a method that is already defined in its superclass.
- Example: A Vehicle class has a method move(). Both Car and Bike inherit move(), but each has its own implementation (overriding it) depending on the type of vehicle.
What are the SOLID principles?
- Single Responsibility Principle (SRP): A class should have only one reason to change. It states that a class should have only one responsibility or purpose. This helps keep classes focused and makes them easier to understand, test, and maintain.
- Open-Closed Principle (OCP): Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This principle encourages designing modules that can be extended with new functionality without modifying their existing code. This promotes code reuse and minimizes the risk of introducing bugs when making changes.
- Liskov Substitution Principle (LSP): Objects of a superclass should be replaceable with objects of their subclasses without affecting the correctness of the program. It ensures that derived classes can be used as substitutes for their base classes without causing unexpected behavior. This principle defines a behavioral contract that derived classes must uphold.
- Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. It promotes the idea of segregating interfaces into smaller and more focused ones, tailored to specific client needs. This prevents clients from being burdened with unnecessary dependencies and provides better flexibility and maintainability.
- Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details; details should depend on abstractions. It encourages decoupling and dependency injection, where dependencies are defined through interfaces or abstractions instead of concrete implementations. This improves flexibility, testability, and modularity.
what is asynchronous programming
Asynchronous programming is a programming paradigm that allows tasks or operations to run independently of the main program flow, without blocking the execution of other tasks. It is particularly useful for operations that can take a long time to complete, such as file I/O, network requests, or database access, enabling the application to remain responsive while those tasks are running in the background.
In asynchronous programming, instead of waiting for a long-running task to finish before proceeding, the program can continue executing other code, and the result of the task is handled when it eventually completes.
What is IoC - Inversion of Control?
Inversion of Control (IoC) is a design principle in software engineering where the flow of control of a program is inverted compared to traditional programming. Instead of the program controlling how objects and services are created and managed, control is “inverted” to a framework or external component. The key idea is that components don’t directly instantiate or manage their dependencies. Instead, those dependencies are provided or “injected” by an external mechanism.
IoC helps in loosely coupling components, making the system more modular, testable, and easier to maintain.
What is Dependency Injection?
Dependency Injection (DI) is a specific implementation of the IoC principle. It refers to the practice of injecting the dependencies (such as services or objects) that a class needs from the outside rather than the class instantiating them itself. The dependencies are injected via one of three common methods:
* Constructor Injection (most common)
* Property Injection
* Method Injection
DI is a way to implement IoC, where an external component (typically an IoC container) provides the dependencies for a class.
What is a Docker file, and what does it define?
A Docker file is a blueprint that defines the steps to create a Docker image, specifying the base image, dependencies, file transfers, and default commands.
What are Docker images, and how are they created?
Docker images are read-only snapshots of environments, created using docker build from Docker files.
How do containers relate to Docker images?
Containers are runtime instances of Docker images, running in isolation with their own filesystem, network, and processes.
What is Docker’s primary purpose?
To simplify the creation of consistent environments and isolate applications from host dependencies.
What is one of Docker’s most significant advantages for software development?
Fast, lightweight, and portable container environments.
What Is OpenAPI?
OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including:
* Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)
* Operation parameters Input and output for each operation
* Authentication methods
* Contact information, license, terms of use, and other information.
API specifications can be written in YAML or JSON. The format is easy to learn and readable to both humans and machines.
What Is Swagger?
Swagger is a set of open-source tools built around the OpenAPI Specification that can help you design, build, document, and consume REST APIs.