Wednesday, October 20, 2010

Xiangjie the nature of abstract class and interface



We know the difference abstract class and interface definitions in the syntax and programming point of view, the distinction between these levels is relatively low-level, nonessential. The section from another level: abstract class and interface design reflected, to analyze the difference between the two. The author believes that this level of analysis to understand the essence of both concepts.

As already mentioned, abstarct class in the Java language embodies a succession of relationships, in order to make a reasonable inheritance, the parent class and derived class must exist between the "is a" relationship, that is the parent class and derived classes in the concept of should be essentially the same (Ref. 銆?銆?in on "is a" relationship at length in-depth discussion, interested readers can refer to). For the interface it is not, does not require interface implementation and interface definition of the concept is essentially the same, only the interface definition of the contract to achieve it. To make discussion easy to understand, following a simple example will be explained.

Consider this example, assume that the problems in our area, there is a abstraction on the Door, the Door is open and the implementation of two moves close, then we can define abstract class or interface that the abstraction of a type ways were defined as follows:

Use abstract class as defined Door:

abstract class Door (abstract void open (); abstract void close ();)

Use the interface as defined Door:

interface Door (void open (); void close ();)

Other specific Door types can use the abstract class approach extends the definition of the Door or implements to use interface define the Door. Appear to use the abstract class and interface is not a big difference.

If you are asking the Door also has alarm function. How do we design a class structure for the example of it (in this case, mainly to demonstrate abstract class and interface design concept reflected in the difference, independent of other aspects of the issue have done Jianhua, or ignore)? Below Luo Lie Chu possible solutions, and from the design level of these different options for analysis.

Solution 1:

Simple increase in the definition of a Door alarm method, as follows:

abstract class Door (abstract void open (); abstract void close (); abstract void alarm ();)

Or

interface Door (void open (); void close (); void alarm ();)

Then an alarm of AlarmDoor definition as follows:

class AlarmDoor extends Door (void open () (...) void close () (...) void alarm () (...))

Or

class AlarmDoor implements Door (void open () (...) void close () (...) void alarm () (...))

This method violates the object-oriented design of a core principle of ISP (Interface Segregation Priciple), the definition in Door to Door concept inherent in the concept of behavioral approach and the other "alarm" behavior methods mixed together . This problem is caused by those who depend only on the Door module concept for "alarm" the concept of change (such as: Modify alarm method parameters) change, and vice versa.

Solution 2:

Since the open, close, and alarm are two different concepts, they should be according to the principle of ISP were representatives of the two concepts defined in the abstract class. Defined methods are: the two concepts are defined using the abstract class methods; the two concepts are defined using the interface means; a concept means using the abstract class definition, another definition of the concept of using the interface mode.

Clearly, Java language does not support multiple inheritance, so the two concepts are defined using the abstract class approach is not feasible. Behind the two methods are feasible, but for their choice is reflected in the concept of problem areas for the understanding of the nature, reflect the design intent is correct and reasonable. We are 11 to analyze, explain.

If the two concepts are defined using the interface means, then reflects two things:

1, we may not have a clear understanding of problem areas, AlarmDoor the concept of nature in the end is the Door or alarm?

2, if we do not understand the problem domain issues, such as: Through the analysis of the problem areas found AlarmDoor conceptual in nature and Door is the same, then we realized when we failed to reveal the correct design intent, because In the definition of these two concepts (both ways using the interface definition) and do not reflect the meaning.

If we understand the problem domain is: AlarmDoor concept of essence in the Door, while it has an alarm function. How are we to design, implementation to reflect specific we mean? Said before, abstract class in the Java language that a kind of inheritance, and inheritance in nature "is a" relationship. Therefore, the concept for the Door, we should use abstarct class way to define. In addition, AlarmDoor has an alarm, indicating it can complete the definition of the concept of the behavior of police, so police can interface define the concept. As follows:

abstract class Door (abstract void open (); abstract void close ();) interface Alarm (void alarm ();) class AlarmDoor extends Door implements Alarm (void open () (...) void close () (...) void alarm ( ) (...))

This approach can basically be able to clearly reflects our understanding of the problem areas, the right reveals our design intent. In fact, that is the abstract class "is a" relationship, interface that is "like a" relationship, we can, as in the choice of a basis, of course, is based on the understanding of problem areas, such as: If we that the concept is essentially AlarmDoor alarm function also has the Door, then the way would turn the definition.

Conclusion

abstract class and interface is the Java language in the definition of abstract class of two ways, among them a great similarity. However, the choice for them but often reflected in the concept of problem areas for the understanding of the essence reflects the design intent is correct, reasonable, because they Biaoxian the concept of the relationship between the Bu Tong (Suiran will be realized demand function). Actually, this is a language of idioms, I hope readers will feel for a friend.

Abstract class and interface for the essential difference between the contents of the will to introduce to you here, hope you understand and learn abstract class and interface help.







相关链接:



XviD to MP4



British GRAMS, Novel Medicine 1000 Chain layout help



Notebook computer repair experience hidden rules



Types of scanners find different types of mini



MPEG to 3GP



Analysys on Yang: Adjustment for a number of ideas through high-level



Good File And Disk Management



AVI to MPEG4



Taught YOU how to DB2 patch



DDos remains a primary threat to a number Of ISP



Business Databases And Tools evaluation



Students This Year, Real Salary Levels Jiemi Fresh



Good Graphic



Regional Manager how to handle high-level interaction with the company



U disk to create running Win98 super mini



Community 2.0 My Community I CALL the shots



Recreation Catalogs



Tuesday, October 5, 2010

Used to create automatic play music listening Pros CD



Burn music CD, is a required course for music lovers, but how to create automatic play audio CDs? If you are listening Pros, surrounded by those listening Pros would use to achieve it.

Hard disk partition on the selected MP3 music files a save folder, here assumed to be "E: Mp3". Open listening Pros installation directory (default is "C: Program FilesTTPlayer"), to which all of the files are copied to the "E: Mp3" folder. At the same time will need to burn MP3 music files and lyrics files are also copied to the "E: Mp3" folder. Double-click the "E: Mp3" directory "TTPlayer.exe" file to start listening Pros, in its main interface, click the "Play File" button to "E: Mp3" directory of all MP3 file into listening Pros the play list.

Listening Pros main interface in the right menu, click on the "chien Options" in the options window on the left navigation bar, click on "Play", and in the right window, check "program starts automatically play" items Click "Save All" button to save the settings.

In the "E: Mp3" folder, create a new text document, enter the following:

[Autorun]

Open = TTPlayer.exe

After the save it as Autorun.inf file. Use Nero burning software such as "E: Mp3" in all the papers are all burned to CD. Thus, as long as Windows opens the CD-ROM AutoPlay feature, then put in the CD drive made in accordance with the above method MP3 music discs, CD-ROM root directory of the system according to the Autorun.inf, will automatically start listening Pros, listening Pros By default, the playlist, it can automatically play MP3 music.

If Windows does not open automatically playback, so users need only right-aligned drive select "Auto Play" will automatically play MP3 music.







Recommended links:



YouTube To WMV



AVI TO MKV



Creating sql database connection in asp.net web



MATROSKA to MPEG



Identify the black and white ash field, rapid correction of color cast photos


In the color correction to digital photos, how to accurately find the image in black and white gray market is a crucial step. This article introduces a fast and convenient technique, as long as there is black and white gray image, we can use this method to help you quickly and accurately find the black and white ash yard. Note that this method is not a panacea, because not all of the images are black and white ash yard. But as long as it has, we can quickly find it.

This is an entry-level digital camera family photos, we calibrate its color, for example, to see how to find the black market, white and gray market.



Color correction before



After the color correction

Identify the black market

1, open the need to correct color photographs. Click the Layers Panel at the bottom of the "Create new fill or adjustment layer" button from the pop-up menu, select "threshold" in the pop-up "threshold" dialog box, drag the slider to the left, then the image blank. Then slowly drag the slider to the right, you will see black pixels continue. First appeared in the black pixel region is the most secret part of the image that black market. Click "OK" button, Photoshop that add an adjustment layer.



Figure 1



Figure 2

2, from the toolbox to select a color sampling tools, in the above steps to transfer out of black pixels in the area click, the image of the black mark place in the points.



Figure 3




[Next]



Identify the white field

1, the threshold adjustment layer "layer thumbnail" on the double, again open the adjustment layer dialog box, move the slider to the far right, the image will become black. Then slowly drag the slider to the left, you will see the continued emergence of the white pixels. First appeared in the white pixel area is the brightest part of the image that white field. Click "OK" button.



Figure 4



Figure 5

2, also to select a color sampling tools, marking a place in the point image of the white.



Figure 6

Find Ash

1, click the background layer, so that is active. Click the Layers Panel at the bottom of the "Create new fill or adjustment layer" button from the menu, select "solid color (solid)", fill in the color pop-up dialog box will be designated as "808080", that is neutral gray . At this point fill adjustment layer should be above the background layer, below the threshold adjustment layer. In the Layers panel, change the layer blend mode "difference (margin)."



Figure 7



Figure 8

2, double-click the threshold layer, adjustment layer dialog box open, will drag the slider to the left, then a blank image. Then slowly drag the slider to the right, you will see black pixels continue. First appeared in the black pixel region is part of the image of a neutral gray, or gray market. Click "OK" button.



Figure 9

3, select the color sampling tools, marking a place at the point of gray images.



Figure 10

Now you can adjust the layers of hidden or deleted. Finally create a new "curve adjustment layer" dialog box, click the Curve icon on the bottom right corner of the three straw, good position under the previous mark, set the black and white ash yard.



Figure 11



Figure 12








Recommended links:



TS To WMV



Training Into The Domestic Game Breakthrough



Evaluation Remote Computing



how to convert divx to divx avi



Infomation File And Disk Management



Zhongguancun business will have been cleaned up and returned Rectifying Zanji



Coreldraw draw cute Doraemon



TV Shopping busy to make a fuss in the credibility of the



"Personal efficiency" and "organizational EFFICIENCY"



AVI to MOV



DAT to WMV



THE reliability of SAS



Fireworks of matting Kung Fu article



Guide Calculators And Converters