Click here to Skip to main content
15,914,444 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: windows TO vista!! Pin
messages26-Feb-08 23:25
messages26-Feb-08 23:25 
Generalcompile error cannot convert 'this' pointer Pin
George_George24-Feb-08 16:39
George_George24-Feb-08 16:39 
GeneralRe: compile error cannot convert 'this' pointer Pin
Stephen Hewitt24-Feb-08 17:31
Stephen Hewitt24-Feb-08 17:31 
GeneralRe: compile error cannot convert 'this' pointer Pin
George_George24-Feb-08 17:46
George_George24-Feb-08 17:46 
QuestionAnybody know where this article went? Pin
netengineer24-Feb-08 16:30
netengineer24-Feb-08 16:30 
GeneralRe: Anybody know where this article went? Pin
Hamid_RT25-Feb-08 6:56
Hamid_RT25-Feb-08 6:56 
GeneralLiskov substitution principle Pin
George_George24-Feb-08 15:55
George_George24-Feb-08 15:55 
AnswerRe: Liskov substitution principle Pin
Rajkumar R24-Feb-08 19:28
Rajkumar R24-Feb-08 19:28 
"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); // error, cannot be subtitutable
     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.
GeneralRe: Liskov substitution principle Pin
George_George24-Feb-08 20:23
George_George24-Feb-08 20:23 
AnswerRe: Liskov substitution principle Pin
Rajkumar R24-Feb-08 20:36
Rajkumar R24-Feb-08 20:36 
GeneralRe: Liskov substitution principle Pin
George_George24-Feb-08 21:02
George_George24-Feb-08 21:02 
GeneralRe: Liskov substitution principle Pin
Rajkumar R24-Feb-08 23:08
Rajkumar R24-Feb-08 23:08 
GeneralRe: Liskov substitution principle Pin
George_George24-Feb-08 23:17
George_George24-Feb-08 23:17 
Generalhelp Pin
gentleguy24-Feb-08 15:25
gentleguy24-Feb-08 15:25 
GeneralRepost! Pin
leckey24-Feb-08 15:40
leckey24-Feb-08 15:40 
GeneralRe: Repost! Pin
gentleguy24-Feb-08 21:04
gentleguy24-Feb-08 21:04 
QuestionRe: Repost! Pin
Rajkumar R24-Feb-08 21:57
Rajkumar R24-Feb-08 21:57 
GeneralRe: Repost! Pin
gentleguy24-Feb-08 23:01
gentleguy24-Feb-08 23:01 
GeneralRe: Repost! Pin
Maxwell Chen24-Feb-08 23:08
Maxwell Chen24-Feb-08 23:08 
AnswerRe: Repost! Pin
Rajkumar R25-Feb-08 1:09
Rajkumar R25-Feb-08 1:09 
GeneralUser Identity Pin
Bram van Kampen24-Feb-08 14:39
Bram van Kampen24-Feb-08 14:39 
AnswerRe: User Identity Pin
Rajesh R Subramanian24-Feb-08 18:22
professionalRajesh R Subramanian24-Feb-08 18:22 
General[Message Deleted] Pin
Shontay24-Feb-08 13:50
Shontay24-Feb-08 13:50 
QuestionRe: Could anyone help me Pin
Rajkumar R25-Feb-08 1:00
Rajkumar R25-Feb-08 1:00 
GeneralRe: Could anyone help me Pin
Shontay25-Feb-08 1:22
Shontay25-Feb-08 1:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.