Oop Assignment
Oop Assignment
**Question 1**
* Can be overloaded (multiple constructors with different parameter lists) to provide flexibility in
object creation.
* **Destructors:** Special member functions (also called finalizers) that are invoked automatically when
an object is garbage collected. They are used to:
* Release any unmanaged resources held by the object (e.g., closing files, releasing memory).
* Can only have one destructor per class, and it takes no arguments.
**Polymorphism:**
The ability of objects of different classes to respond to the same method call in different ways. This is
achieved through inheritance and virtual methods:
* **Inheritance:** Allows subclasses to inherit properties and methods from parent classes.
* **Virtual methods:** Methods declared as `virtual` in a base class can be overridden in derived classes
to provide specialized behavior. When a virtual method is called on an object, the actual method
executed depends on the object's type at runtime (dynamic binding).
* **protected:** Members are accessible from the same class and derived classes.
* **internal:** Members are accessible only from the same assembly (compiled unit of code).
* **protected internal:** Members are accessible from the same assembly and derived classes in other
assemblies.
* **Method Overriding:**
* Occurs in inheritance when a derived class redefines a virtual or abstract method inherited from a
base class.
* **Method Overloading:**
* Occurs within the same class when multiple methods have the same name but different parameter
lists.
* Allows methods with the same name to perform different actions based on the types and/or
number of arguments provided.
**Question 2**
**Exceptions in C#:**
* **System.NullReferenceException:** Occurs when a reference variable is accessed but does not refer
to a valid object (null).
* **System.ArgumentException:** Occurs when an invalid argument is passed to a method.
* **System.IO.FileNotFoundException:** Occurs when a file cannot be found. (There are many more
built-in and custom exceptions.)
* **While loop:**
* Useful when the number of iterations is not known beforehand or depends on user input.
* **For loop:**
* Often used when the number of iterations is known in advance (e.g., iterating through elements of
an array).
* **continue:** Skips the remaining code in the current iteration of the loop and jumps back to the
beginning of the next iteration.
**Question 3**
**Components of the Visual Studio IDE:**
* **Toolbox:** Provides drag-and-drop components for building graphical user interfaces (GUIs).
* **Properties Window:** Shows properties of selected elements and allows editing their values.
* **Output Window:** Displays compiler output, debugging information, and other messages.
* **Debugger:** Allows you to step through code line-by-line, set breakpoints, and examine variables.
* **Delegates:** Function pointers that refer to methods that share a compatible signature (return type
and parameters).
* Used to create loosely coupled callbacks, allowing methods from different classes to be invoked.
* **Events:** A mechanism for notifying interested objects of an event that has occurred.
A Version Control System (VCS) is a software tool that tracks changes to files over time. It's like a giant
"undo/redo" button for your entire codebase, allowing you to see past versions, revert to previous
states, and collaborate effectively on projects.
* **Collaboration:** With VCS, multiple developers can work on the same codebase simultaneously
without conflicting with each other. VCS merges changes and helps identify potential conflicts before
they cause problems.
* **Rollback:** If you introduce a bug, you can easily revert to a previous working version of the
codebase. This saves time and frustration compared to manually trying to fix a broken system.
* **Branching and Merging:** VCS allows developers to create branches of the codebase for
experimentation or parallel development efforts. They can then merge changes back into the main
codebase when ready. This improves development flexibility and efficiency.
* **Version Control for Assets:** VCS isn't just for code! It can also track changes to other project assets
like images, documents, and configuration files, ensuring everyone is working on the latest versions.
Mocking is a technique used in unit testing to create simulated objects that mimic the behavior of real
objects used by the code you're testing. Mocks allow you to test specific units of code in isolation
without relying on external dependencies or external systems that might be unavailable or difficult to
control during testing.
* You define the expected behavior of the mock object, including the responses it should provide when
methods are called on it.
* Your unit test interacts with the mock object instead of the real object.
* You can then verify whether the unit test caused the mock object to be interacted with in the
expected way, indicating correct behavior of your code.
Mocking is particularly useful for:
* Testing code that interacts with external systems like databases or APIs, which can be slow or
inconvenient to use during every test.
* Isolating specific dependencies to ensure your code behaves as intended regardless of external
factors.
* Making tests faster and more reliable by removing the need to interact with external systems.
There are various mocking frameworks available depending on the programming language you're using.
Test-Driven Development (TDD) is a software development approach where you write unit tests
**before** writing the actual code. Here's the basic TDD cycle:
1. **Write a failing test:** You start by defining a test case that represents a specific functionality you
want to implement. This test will initially fail because the code that fulfills that functionality hasn't been
written yet.
2. **Write the minimal code to make the test pass:** Focus on writing just enough code to pass the
failing test. This ensures you're only writing code that addresses the specific functionality you identified
in the test.
3. **Refactor and improve the code:** Once the test passes, you can refactor the code to improve
readability, maintainability, and performance. You can also write additional tests to cover edge cases
and ensure overall code quality.
4. **Repeat:** Go back to step 1 and write another failing test for a new piece of functionality.
* **Better design:** Focusing on tests first encourages you to think about the desired functionality from
the outset.
* **Easier debugging:** Tests can help pinpoint issues more easily as you develop the code.
* **Increased confidence:** A suite of passing tests provides confidence in the code's correctness.
TDD can have a steeper learning curve initially, but it can lead to more robust and maintainable code in
the long run.