Why do we need Adapter when we can use an Interface?
Adapter is used in cases when we need to use two incompatible interfaces. The adapter provides the client what interface it needs while the adapter internally calls the other interface.
Adapter is used in cases when we need to use two incompatible interfaces. The adapter provides the client what interface it needs while the adapter internally calls the other interface.
public async Task<string> DoSomething() {
var res = await httpClient.GetAsync("SOME_GET_API");
return await res.Content.ReadAsStringAsync();
}
public class MyClass {
~MyClass() {
// any custom release operations
}
}
Using the C# language constructs, you cannot explicitly call the base function from outside the scope of A or B. If you really need to do that, then there is a flaw in your design - i.e. that function shouldn't be virtual to begin with, or part of the base function should be extracted to a separate non-virtual function.
class A
{
virtual void X() { Console.WriteLine("x"); }
}
class B : A
{
override void X() { Console.WriteLine("y"); }
}
class Program
{
static void Main()
{
A b = new B();
// Call A.X somehow, not B.X...
}
}
you can write multiple catch blocks for a try block, but only the exception block that closely matches the exception is executed.