Design Pattern "headfirst design pattern"

Source: Internet
Author: User
Tags multiple inheritance in java
This is a backup of my Reading Notes: From: http://blog.4kiki.net/hsy75/article/1306/
========================================================== ========================================================== ====================================
[8-21] Finish the creaters of head first series and read the table of contents which
Include the basic introduce of design patterns. Start to read the how to use this
Books. (page53)
[8-23] Intro to design patterns. Joe make a flaw while use the inheritance, and he
Want to use the override method to solve the problem. Joe then decided to use
Added interface to implement duck feature. But this subclasses implement wocould creat
Maintenace nightmare, what the design pattern wocould Save As, (page 60)
[8-24] design principle: Take what varies and "encapsulate" it so it won't affect
Rest of your code. The writer question us the method to "separating what changes from
What stays the same"
[8-25] design principle: program to an interface, not an implementation. Program to
Interface really means program to a supertype: Here Eric give us some details
Explaination, here, as I ask a super guy of OO, he said that in Ood, the program
An interface is realized by program to a supertype. Another word that program to
Supertype is a method to realize the program to an interface in Ood.
Implement the fly and quack behaviors. Using a setter method to make the behavior
Dynamically change. The concrete behavior is implemented on the interface, but not
One which we can called concrete class. take care the versus of each. The Java do
Have the construct interface, but the interface here writer means is different. It
Is a wide use here.
[8-26] integrating. To realize the integrate of duck behavior, Joe need to add
Instance variables (quackbehavior) used for interface which reference to
Specific behavior object (quackbehavior) and then modify the method (quackbehavior) in
The (duck) class, so that the object (duck) can delegates the behavior (quack one
The concrete implement class of quackbehavior) to the object (quackbehavior
) Referenced by quackbehavior.
In my understanding, as view point from the memory, while the mallardduck
Inherites (constructor initializes) the duck class, the superclass 'reference is
The concrete object quack (the same share store place in the memory), so
Responsibility for the quack is delegated to the quack object and then we get
Real quack which we want.
[Q1] What can we tell the declared is a interface type but not a concrete class
Implementation type? A interface is a part of the code we do not care what kinds
Object it is, all we care about is that the object shoshould knows how to implement.
In sub class (mallardduck), just made the instance variable (quackbehavior) Delegates
To the real behavior quack, for detailes.
Inherits the instance variables (quackbehavior) from the super class (duck) which
Reference to the behavior object (quackbehavior), then "quackbehavior = new quack"
Vivilife_design pattern "headfirst Design Pattern"
Use the quack class to handle the quack, so when the super class (duck)'s Method
(Specified quack) is called, the interface quack is delegated to the quack object. When
The mallardduck is instantiated, its constructor initializes the mallardduck's
Inherited quackbehavior instance variable to a new instance of Type quack.
[10-13] 71 test the duck code: [notic] use the abstract class so that the Polymorphism
Can work, the abstract class is a class can not be instantiated. [notic] interface in
Java, means: its member are not implemented. [Refer to] interface vs abstract class:
1 interface class, 2calss. vs. interfacevs. Abs class. The interface in driver benifit
Advantages to multiple inheritance in Java. Design Principle: favor composition over
Inheritance.
God, I has just finished learn the first design pattern: Strategy pattern: Define
Family of algorithms, encapsulates each one, and make them interchangeable, stategy
Lets the algorithm vary independently from clients that use it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.