How to Insert a Override Function into a If Else Statement

Different Override method based on condition

You can create different implementations of an interface which shares the dispatchTouchEvent method. Take a look at the Strategy Pattern.

Multiple IF functions in Excel: how to override on IF statement if another IF is true.

You need to use the AND(logical1, [logical2], ...) function of Excel in your IF statements to concatenate more conditions. (read more about AND here: https://support.office.com/en-us/article/AND-function-5f19b2e8-e1df-4408-897a-ce285a19e9d9)

Also you need to turn the logic around. You need to check if all fields are TRUE first. Then if field 2-8 are TRUE and so on...

So your statement would look something like this:

IF(AND(A8=TRUE,A7=TURE, A6=TRUE, ...), 1,
IF(AND(A8=TRUE,A7=TURE, ...), 2,
IF(AND(A8=TRUE, ...), 3,)
)
)

How to override a method only if a condition is found to be true?

You can't make a runtime decision about whether a method is overridden (without generating classes dynamically, which is complicated [and I have no idea if it's supported in Dalvik]).

Just check your condition in the method:

protected void attachBaseContext(Context base) {
if (this.value) {
// Your special behavior
super.attachBaseContext(ZeTarget.attachBaseContext(base,this));
} else {
// The super's behavior, as though you hadn't overridden the method
super.attachBaseContext(base);
}
}

Method Override with some condition in Console application

In ChildClass you can do something like this:

public partial class ChildClass : MainCLass
{
public override void Method1()
{
if(condition)
{
base.Method1();

return;
}

//YOUR LOGIC
}
}

EXAMPLE

public class A
{
public virtual void MethodA()
{
Console.WriteLine("A:MethodA");
}
}

public class B : A
{
public bool CallBase { get; set; }

public B()
{
CallBase = false;
}

public override void MethodA()
{
if (CallBase)
{
base.MethodA();

return;;
}

Console.WriteLine("B:MethodA");
}
}

class Program
{
static void Main(string[] args)
{
A a = new A();
B b = new B();

a.MethodA();
b.MethodA();

b.CallBase = true;

b.MethodA();

A c = new B();

c.MethodA();

A d = new B(true);

d.MethodA();

Console.ReadKey();
}
}

Output

A:MethodA
B:MethodA
A:MethodA
B:MethodA
A:MethodA



Related Topics



Leave a reply



Submit