<> Object oriented day 8 :

<> First day of submarine game :

* Design 6 Class , Design World Class and test
<> The second day of submarine game :

* to 6 Add constructor to class , And test
<> Submarine game day 3 :

* Design reconnaissance submarine array , Torpedo submarine array , Mine submarine array , Mine array , Deep water bomb array , And test
* Design SeaObject Superclass , Design 6 Class inherits superclass
* to SeaObject Two construction methods are designed ,6 Each class is called separately
<> Submarine game day 4 :

* Array of reconnaissance submarines , Torpedo submarine array , The mine submarine array is uniformly combined into SeaObject array , And test
* stay 6 Overridden in a class move() move , And test
* Draw window
<> Submarine game day 5 :

* Add an access control modifier to a member in a class
* establish Images Picture class
<> Submarine game day 6 :

* The width and height of the design window are constant , Make changes where appropriate
* Draw an ocean map , Painting object :
* If you want to draw an object, you need to get the image of the object , Each object can get pictures ,
It means that the behavior of obtaining pictures is a common behavior , So the design is SeaObject In class ,
The behavior of each object to get pictures is different , So it is designed as an abstract method
---- stay SeaObject Design abstraction method in getImage() Get picture
* stay 6 Overridden in a derived class getImage() Get a picture of the object
---- rewrite getImage() Get picture
* Because only living objects need to be drawn into the window , So you need to design the state of the object ,
Every object has a state , It means that the status is a common attribute , So the design is SeaObject in ,
States are generally designed as constants , Simultaneous design state Variable represents the current state
---- stay SeaObject Design state constant in LIVE,DEAD,state Variable represents the current state
In later business, you also need to judge the status of the object , Each object can judge the state ,
It means that the behavior of judging the state is a common behavior , So the design is SeaObject in ,
The behavior of each object to judge the state is the same , So the design is a common method
---- stay SeaObject Medium design isLive(),isDead() Judge the state of the object
* With all the data, you can start painting , Every object can be painted ,
It means that the behavior of the painting object is a common behavior , So the design is SeaObject in ,
The behavior of each object is the same , So the design is a common method
---- stay SeaObject Medium design paintImage() Draw pictures --------- How to draw , Not required to master
* The behavior of the painting object is done well , In the window World Call in :
* Prepare object
* rewrite paint() method ------ call paintImage() method
<> Day 7 of submarine game :

*
Submarine admission :

* Submarines are produced by windows , So in the window World Design in class nextSubmarine() Generate submarine object
* Submarine admission occurs regularly , So in run Call in submarineEnterAction() Realize submarine admission
stay submarineEnterAction() in :
each 400 millisecond , Get submarine object obj,submarines Capacity expansion , take obj Add to submarines On the last element
stay run() Call in submarineEnterAction() after , Must call repaint() Method to redraw

*
Mine entry :------------- Only part of today ( The rest will be done on Friday )

* Mines are launched by mine submarines , So in MineSubmarine Medium design shootMine() Generate mine object
* Mine admission occurs regularly , So in run Call in MineEnterAction() Realize mine admission
stay MineEnterAction() in :
each 1000 millisecond …-------------- Speaking on Friday
*
Ocean object movement ( Excluding warships ):

* Object movement is a behavior common to all objects , So in superclass SeaObject Design abstraction in move() To achieve mobile ,6 Overridden in a derived class
* The movement of ocean objects occurs regularly , So in run Call in moveAction() Realize the movement of ocean objects
stay moveAction() in :
Traverse all submarines and let them move , Traverse all mines and let the mines move , Traverse all deep-water bombs and let the deep-water bombs move
<> Submarine game day 8 :

*
Deep water bomb admission :

* Deep water bombs were launched by warships , So in Battleship Medium design shootBomb() Deep water bomb launch
* The entry of the deep-water bomb was triggered by the event , So override in listener keyReleased() Key lifting event :
* Judge if the key is a space bar , Then get the deep-water bomb object obj,bombs Capacity expansion , take obj Add to last element
*
Warship movement :

* The act of moving a warship into a warship , So in Battleship Medium design moveLeft() Shift left ,moveRight() Shift right
* The warship movement is triggered by the event , So in the listener keyReleased() Key lifting event :
* Judge if the key is the left key head , Then the warship moves to the left , If the key is a right key head , Then the warship moves to the right
*
Delete out of bounds objects ( submarine , mine , Deep water bomb ):------ Guaranteed performance

* stay SeaObject Medium design isOutOfBounds() Detect whether the submarine crosses the boundary ,
stay Bomb/Mine Medium rewrite isOutOfBounds() Detection of deep-water bombs / Whether the mine crosses the boundary
* Deleting out of bounds objects occurs regularly , So in run Call in outOfBoundsAction() Delete out of bounds objects
stay outOfBoundsAction() in :
Traverse all submarines / mine / Deep water bomb , If the judgment goes beyond the boundary :
Replace the out of bounds element with the last element , Volume reduction ( Shrinking is the last element )
*
Design interface :

* Design EnemyScore Scoring interface , Scoring interface between reconnaissance submarine and torpedo submarine
* Design EnemyLife Get life interface , Realization of life interface for mine submarine
<> review :

* Member inner class :-------------- understand
Nested class in class , External class only , Invisible to the outside world , Inner class objects are usually created in outer classes
Members of the inner class that have direct access to the outer class ( Including private )
---- There is an implicit reference in the inner class to the external class object that created it ------- External class name .this------API Can be used when
* Anonymous Inner Class :------------------ Greatly simplify the code
If you want to create a class ( Derived class ) Object of , And the object is created only once , Anonymous inner classes are recommended
The default external variable of anonymous inner class is final of ------------------------------API Can be used when
All classes have independent .class
<> note :

* Interface :
* Is a reference data type
* from interface definition
* Can only contain constants and abstract methods
* Interface cannot be instantiated (new object )
* Interfaces need to be implemented / Inherited , Implementation class / Derived class :
---- All abstract methods must be overridden
* A class can implement multiple interfaces , Separated by commas , If you inherit and implement , It should be inherited before implementation
* Interfaces can inherit interfaces // Interface demonstration public class InterfaceDemo { public static void main(String
[] args) { //Inter5 o1 = new Inter5(); // Compilation error , Interface cannot be instantiated Inter5 o2 = new Doo();
// Upward modeling ( Can be modeled as the interface it implements ) Inter4 o3 = new Doo(); // Upward modeling } } // Demo interface inheritance interface interface
Inter4{ void show(); } interface Inter5 extends Inter4{ void test(); } class Doo
implements Inter5{ public void test(){} public void show(){} } // Multi implementation of demo interface
interface Inter2{ void show(); } interface Inter3{ void test(); } abstract class
Boo{ abstract void say(); } class Coo extends Boo implements Inter2,Inter3{
public void show(){} public void test(){} public void say(){} } // Implementation of demo interface
interface Inter1{ void show(); // The default access permission is public void test(); } class Aoo
implements Inter1{ public void show(){} // Rewrite abstract methods in interfaces , Access rights must be public public void
test(){} } // Demonstrates the syntax of the interface interface Inter{ public static final int NUM = 5;
// The access rights of members in the interface can only be public of public abstract void show(); int COUNT = 6; // default public
static final void say(); // default public abstract //int number; // Compilation error , Constants must be declared and initialized at the same time
//void test(){} // Compilation error , Abstract methods cannot have method bodies }
<> Essence note :

* Interface :
* Is a reference data type
* from interface definition
* Can only contain constants and abstract methods
* Interface cannot be instantiated (new object )
* Interfaces need to be implemented / Inherited , Implementation class / Derived class :
---- All abstract methods must be overridden
* A class can implement multiple interfaces , Separated by commas , If you inherit and implement , It should be inherited before implementation
* Interfaces can inherit interfaces
<> supplement :

* Boundary crossing detection diagram :

* relationship :
* Classes and classes --------------------- inherit extends
* Interfaces and interfaces --------------- inherit extends
* Classes and interfaces ------------------ realization implements
* Design rules :
* Attributes and behaviors common to all derived classes , Draw into superclass --------------- Pumping commonness
* If all objects behave the same , Design as common method
If the object behaves differently , Design as abstract method
* Attributes and behaviors shared by some derived classes , Draw into the interface
An interface is an extension of the singleness of inheritance --------------------------- Implement multiple inheritance
* Meaning of interface :
* Implement multiple inheritance
* Developed a set of standards , rule

Technology
Daily Recommendation
views 267
views 232
views 231