💲 10 Preguntas de Entrevista para Desarrolladores NET | C# Consejos y Trucos #pmfoxtechnologies
What are the Principles of Object-Oriented Programming?
Key Principles of OOP
- Encapsulation: This principle involves restricting access to certain components of an object, allowing only specific information to be visible. Internal functionalities that should remain hidden are kept private.
- Abstraction: Focuses on isolating an element from its context, emphasizing what an object does rather than how it does it.
- Inheritance: The ability to create new objects based on existing ones, where a parent class (superclass) can pass attributes and methods to a child class (subclass). This promotes code reuse.
- Polymorphism: Refers to the capability of an object to exhibit different behaviors in response to the same action, often implemented through inheritance.
Understanding Classes and Objects
Definitions and Examples
- Class Definition: A class is a data structure used for creating objects, consisting of properties (attributes) and methods (functions). For example, a "Car" class may include properties like speed, brand, model, and color.
- Object Instantiation: An object is an instance of a class. For instance, creating a "Toyota" object from the "Car" class with predefined values such as brand = Toyota, model = Corolla, color = red.
- Constructor Usage: Newer implementations in C# allow for simpler instantiation without explicitly defining 'new Car'. Objects can also be created without default values.
Classes vs. Objects
Differences Explained
- A class serves as a blueprint or model that does not consume memory until instantiated into an object. An object represents this blueprint in memory and utilizes resources.
Interfaces and Abstract Classes
Key Concepts
- Interface Definition: An interface outlines actions that an object can perform by declaring method signatures publicly without implementation details.
- Abstract Class Definition: An abstract class cannot be instantiated directly; it defines methods that may have implementations but primarily serves as a base for other classes.
Differences Between Interfaces and Abstract Classes
- Abstract classes use the keyword 'abstract', while interfaces use 'interface'. Only one abstract class can be inherited at once; however, multiple interfaces can be implemented by a single class.
- Access modifiers differ; all members in an interface must be public whereas abstract classes can have various access levels. Additionally, abstract classes may contain implemented methods while interfaces only declare them.
Special Keywords in OOP
Reserved Keywords Explained
- Sealed Keyword: Used when inheriting from another class but wanting to prevent further inheritance of specific methods within derived classes.
Access Modifiers in Programming
Introduction to Access Modifiers
- The discussion begins with the importance of using methods repeatedly across different parts of code, allowing for quick access without constant instantiation.
- A prompt is made for viewer engagement, asking for feedback on the video and suggestions for future questions.
Types of Access Modifiers
- Four main access modifiers are introduced: public, protected, internal, and private.
- Public: No restrictions; accessible from anywhere within the project.
- Protected: Limited access to the containing class or derived types.
- Explanation of how inheritance works with protected members:
- Derived classes can inherit attributes and methods from their parent class.
Detailed Breakdown of Access Levels
- Internal access modifier:
- Limits accessibility to the current assembly only; must be accessed within the same assembly context.
- Private access modifier:
- Restricts access solely to the containing type (class); private methods or properties cannot be accessed outside that class.
Additional Access Modifiers
- Two additional modifiers mentioned:
- Internal Protected: Accessible within the current assembly and by derived types.
- Private Protected: Restricted to the containing class and its derived types within the same assembly.
Conclusion & Future Content