Same Ideas, Different Terms
               
      All OOP languages have the following concepts
      • classes, objects,factory object
      • instances, objects
      • message passing, method lookup,memberfunction invocation,method binding
      • methods, member function, method function
      • inheritance, sub classing
       
              Encapsulation and Instantiation
               
      classes provide two very important capabilities:

      Encapsulation: purposeful hiding of information, thereby reducing the details to be remembered/communicated
       
      Instantiation: create multiple instances of an abstraction
       

              Internal and external views

               

         Push                       |            const limit = 300
                                        |
         Pop                         |            var current Top : 0 ..Limit
                                        |
         Top                         |             var : array [ 1 .. limit ] of integer
         

                              State - Instance Variables
         
        Instance -  a representative    or example of a class
        Instance Variable - the state, or data values, maintained internal to a class

        Record information about instance variables on the back of the CRC card
                   - clients can see front of CRC card
                   - implementors can see on the back of the CRC card

     
              Example - Playing Card

              |--------------------------------------------------------------|
              |      Card                                           ;       |
              |     Maintain and return suit and rank                         |
              |    Return color of face                                         &n bsp;      |
              |    Maintain face-up or face-down status              |
              |    Draw card on playing surface                                |
              |     Erase card on playing surface                                |
              |-------------------------------------------------------------|

      This is the front face of the CRC card
       
                                   Playing Card backside - data Areas

                               |-------------------------------------------------------------|

              | Card -implementation information         |
              |                                       &n bsp;                     |
              |        int suit value -0- heart, 1- club                         |
              |             2- diamond , 3- spade                                     |
              |          int rank value -1 through 12                             |
              |          boolean faceup                                        & nbsp;         |
              |                                        ;                                          &n bsp;   |
              |-------------------------------------------------------------|
               
          the back can record about the internal state of the instance.
           
           
               Revision of Card

              |----------------------------------------------------------------|
              |  Card                                     &nb sp;                |
              |    suit( ) - return suit value                                       &nbs p;   |
              |    rank( ) - return rank value                                        |
              |     color( ) - return color value                                       |
              |     erase(x,y ) - erase card image                                    |
              |    draw( x,y) - draw card image                                       |
              |    faceUp( ) , flip ( ) - test or flip card                            |
              |--------------------------------------------------------------- |

        we refine the behavior by providing explicit function names and arguments types.

                                Interface and implementation

        Distinction between interface and implementation is manifest in different ways:
         

        •  within class ,separation between interface and implementation
                Example :  public and private fields in c++ and java
         
        •   Interface descriptions and implementation bodies appearing in separate places
                Example : .h files and *.cpp files in c++
             
                Varieties of classes
                 
        Data manager : principal responsibility is to maintain data values
               example: playing card - maintain suite value information

        Data sink or source : interface to data generator or consumer, no data itself
               example : input/output stream objects - files, i/o devices

        View or observer class: display objects graphically, not the object itself

          •      Viewing tasks are different from data manipulation tasks
          •      an object might have different views
        Facilitator or helper class: maintain little/no state, but assist with complex tasks
               Example: painting assistant ( Pen , Canvas, Edit box ) for graphics output device
         
                      Classes and Methods in java
          Java is similar to c++ , but
           
          • no preprocessor, global variables, enumerated data types
          • methods always defined directly in  the class definitions
          • Keywords public private applied individually to features
          • Boolean data type is boolean , not bool
          • Object references instead of pointers
          • All methods must specify a return type
           
                Playing Card in java
                 
          class Card {
                    // static values for colors and suits
          final public int red =0;
                final public int black =1;
                final public int spade =0;
                final public int heart =1;
                final public int diamond =2;
                final public int club =3;

                    // constructor
        Card (int sv, int rv) { s= sv; r= rv; faceup = false; }

                // mutator
        public void flip ( ) { faceup = ! faceup }

              // accesors
        public int rank ( ) { return r; }

        public int suit ( ) { return s; }

        public int color ( ) {

         if (suit( ) = = heart || suit = = diamond )
                 return red;
                 return black; }

        public boolean faceup ( ) { return faceup; }

         // perform other actions

        public void draw( Graphics g, int x,int y ) {

        . . ./* omitted */. . .

        // data fields

        private boolean faceup;
        private int r;
        private int s;

        };