The adapter/wrapper pattern is to add more functions to code that has already been used by some classes so that it can be used by new classes that have more functions. In the following sample code, the interfaces can be replaced by abstract classes or ordinary classes and the corresponding implements by extends.
//The already established system
public interface WalkingClub {
public void walking();
}
public class AngelWalkingClub implements WalkingClub {
public void walking() {
//one walking should have flat and mountainous roads
}
}
public class HappyWalkingClub implements WalkingClub {
public void walking() {
//one walking should have at least 3 members
}
}
//Adapt for new classes
public interface SportClub extends WalkingClub {
public void running();
public void swimming();
}
public class HealthySportClub implements SportClub {
public void walking() {
//Should rest for each 30 minutes of walking
}
public void running() {
//No one should have knee problems
}
public void swimming () {
//The person has to like water
}
}
----------------------------------------------------------------------------------------------------------------
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
//The already established system
public interface WalkingClub {
public void walking();
}
public class AngelWalkingClub implements WalkingClub {
public void walking() {
//one walking should have flat and mountainous roads
}
}
public class HappyWalkingClub implements WalkingClub {
public void walking() {
//one walking should have at least 3 members
}
}
//Adapt for new classes
public interface SportClub extends WalkingClub {
public void running();
public void swimming();
}
public class HealthySportClub implements SportClub {
public void walking() {
//Should rest for each 30 minutes of walking
}
public void running() {
//No one should have knee problems
}
public void swimming () {
//The person has to like water
}
}
----------------------------------------------------------------------------------------------------------------
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.
No comments:
Post a Comment