|
http://www.codeproject.com/useritems/GINA_SPY.asp
|
|
|
|
|
Did you search on the codeproject?
|
|
|
|
|
Hello everyone,
I am learning Liskov substitution principle,
http://en.wikipedia.org/wiki/Liskov_substitution_principle
But the description is not common senses. Now I understand this principle to be, if we have some methods in base class, then we also need to implement the methods in derived class. My understanding correct? Anything else missing?
thanks in advance,
George
|
|
|
|
|
"In object-oriented programming, the Liskov substitution principle is a particular definition of subtype, which is based on the notion of substitutability; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program".
"Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T."
for example;
template <typename T>
class propertyQ
{
public:
static void QMethod1(T &objT)
{
objT.operate1();
}
static void QMethod2(T &objT)
{
objT.operate2();
}
};
class superTypeA
{
protected:
int m_iContext;
public:
superTypeA()
: m_iContext(0)
{
}
void operate1()
{
m_iContext = 1;
}
void operate2()
{
m_iContext = 2;
}
};
class subTypeA : public superTypeA
{
public:
void operate2()
{
m_iContext = 21;
}
};
class subTypeB : private superTypeA
{
public:
void operate2()
{
m_iContext = 21;
}
};
int main()
{
subTypeA objA;
subTypeB objB;
propertyQ <subTypeA>::QMethod1(objA);
propertyQ <subTypeB>::QMethod1(objB);
return 0;
}
class propertyQ is written based on the supertype class superTypeA. Here subtype, class SubTypeA, is subtitutable for supertype class, superTypeA, for the property, class propertyQ, without altering the program and is said to follow Liskov substitution principle; while subtype, class SubTypeB, uses private inheritance and cannot be substitutable for supertype, class superTypeA and is said to violate Liskov substitution principle.
George_George wrote: Now I understand this principle to be, if we have some methods in base class, then we also need to implement the methods in derived class. My understanding correct?
No, look at the above example, subtype, class subTypeA, overrides only method, void operate2(), while the method, void operate1() is inherited from superclass, class superTypeA.
here i think u misuderstood between, nominal subtype and structural subtype; in OOP, nominal subype is induced by inheritance while structural subtype is that eventhough u didnot inherit from base class, class superTypeA, if u r implementing all the functions in every class you are able to apply the property, class propertyQ.
George_George wrote: But the description is not common senses.
does my explaination makes sense.
|
|
|
|
|
Thanks Rajkumar!
Your reply is great!!
Most of my confusions are solved. Just one point about structural subtype, you mentioned below,
Rajkumar R wrote: structural subtype is that eventhough u didnot inherit from base class, class superTypeA, if u r implementing all the functions in every class you are able to apply the property, class propertyQ.
What means "if u r implementing all the functions in every class" and "you are able to apply the property, class propertyQ"? What do you mean all the functions and every class?
regards,
George
|
|
|
|
|
George_George wrote: What means "if u r implementing all the functions in every class" and "you are able to apply the property, class propertyQ"? What do you mean all the functions and every class?
struct subTypeA
{
subTypeA()
: m_iContext(0)
{
}
void operate1()
{
m_iContext = 1;
}
void operate2()
{
m_iContext = 2;
}
private:
int m_iContext;
};
struct subTypeB
{
subTypeB()
: m_iContext(0)
{
}
void operate1()
{
m_iContext = 1;
}
void operate2()
{
m_iContext = 2;
}
private:
int m_iContext;
};
it is obvious.
now the propery q(subTypeA) and q(subTypeB) both works
propertyQ <subTypeA>::QMethod1(objA);
propertyQ <subTypeB>::QMethod1(objB);
|
|
|
|
|
Thanks Rajkumar,
My stupid before.
regards,
George
|
|
|
|
|
George_George wrote: My stupid before.
I actually used the sample propertyQ() as a template class to address both the nominal and structural subtype.
otherwise i can only address nominal type if i used the following example;
void propertyQ(superTypeA *obj)
{
obj->operate1();
}
then
subTypeA objA;
subTypeB objB;
propertyQ(&objA);
propertyQ(&objB);
*__w64 ' to 'superTypeA *' exists, but is inaccessible
In this case i cannot address structural subtype.
|
|
|
|
|
Thanks Rajkumar,
My question is answered.
regards,
George
|
|
|
|
|
dear all
i would like to generate such code: i have to Gaussian size mask according to different sigma value,anyone has such code? please help me, thanks a lot.or anyone know how to determine Gaussian mask size according to different sigma value.
Li Zhiyuan
|
|
|
|
|
Looks like someone already answered this question to someone who has been here long enough to know not to title messagees with 'help.'
|
|
|
|
|
thanks, friend, yes, they answered, but not exactly, so i still didn't solve it. thanks a lot.
Li Zhiyuan
|
|
|
|
|
And friend, i remember u got comments, theory, pseudo code, code in C#, i think you are expected C++ code only. if so, why can't you port to C++ as needed.
|
|
|
|
|
thanks for your reminder, i didn't find, can you send me again. thanks a lot.
Li Zhiyuan
|
|
|
|
|
Go to your own profile, and click the "Messages posted" link.
Maxwell Chen
|
|
|
|
|
li zhiyuan wrote: thanks for your reminder, i didn't find, can you send me again.
code in C#: [^]
pseudo code: [^]
comments: [^]
theory: [^]
see maxwell's comment also.
gentle query: why these are not useful?
|
|
|
|
|
Is there any way of establishing whilst running an installation program, whether the session running it has administrator authority.
Bram van Kampen
|
|
|
|
|
IsUserAnAdmin()[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Shontay wrote: this program is surposed to do the same but by using another parameter
not clear, can you pleace be more specific.
|
|
|
|
|
I meant by returning the lines by using a different function
|
|
|
|
|
printf() ?
what does your "printLine()" do?
|
|
|
|
|
Shontay wrote: ...but by using another parameter.
This makes no sense. What function's parameter are you referring to? As it stands, the printLine() function is being sent one argument. Are you implying that printLine() takes an additional argument?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Do you have printLine codes?
|
|
|
|
|
Hey Guys,
Do any of you know of any win32 api or DeviceIOControl commands that allow me to:
Retrieve the current channel my wifi adapter is communicating on?
thank you,
Michael
|
|
|
|