TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tommy Sin
NA
19
104.3k
Regarding Liskov substitution principle
May 31 2011 4:01 PM
I read an article saying
Liskov substitution principle
(
LSP
)
is a principle in
object-oriented programming
. It states that, in a
computer program
if S is a
subtype
of T, then objects of
type
T may be replaced with objects of type S (i.e., objects of type S may be
substitutes
for objects of type T), without altering any of the desirable properties of that program (correctness, task performed, etc.).
I believe I understand most of it but I have one concern; what happens if overring occurs in the subType? Is it not going to change the correctness and task performed by the object of the subtype S that replaces the object of the type T?
For ex,
Class S
{
public void virtual GetNumber()
{
return 4;
}
}
Class T : S
{
public void override GetNumber()
{
return 10;
}
}
In this case, if an object of type T replaces the object of Type S, I will change the correctness and task performed.
Can anyone help?
Thanks in advance,
Reply
Answers (
1
)
Testing wp7
Rollback and Commit command in Transaction?