1 / 12

Inner and Anonymous Classes

Inner and Anonymous Classes. Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and write procedural-like code.

cathyn
Download Presentation

Inner and Anonymous Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inner and Anonymous Classes • Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and write procedural-like code. • Often times, no one but the enclosing class cares about an object. In this case, you may consider using inner or anonymous classes.

  2. Intro to Data Structures in Java • Single Lined List • Stack • Binary Tree • others...

  3. WindowsBuilderPro by Google • http://download.eclipse.org/windowbuilder/WB/release/R201109201200/3.7/ • b,y,c,n,s,l,d,f,str; get rid of these in Window || Preferences || Java || Code Style || Fields. Otherwise, they will hose you in WB.

  4. Constructors • Constructors are optional. If your class is just a static driver; i.e. it just has a static main method, then no need to instantiate it; and no need for constructor. • If your class is a "java bean" -- a class that models a real world object (noun) in your system, then it should have a constructor. House, Car, Person, etc. • If you don't provide a constructor, a no-args constructor is provided automatically. • You can, and often want, more than one constructor with different signatures. • You call a constrcutor with the 'new' keyword.

  5. Model a system • Object-oriented programming is about modelling a system. • Write the problem out as requirements -- this will essentially be a math world problem (your favorite kind to solve!) • Your computer objects map directly to real-world objects (nouns). • Your methods map directly to real-world actions (verbs).

  6. Write a very simple application for a contact manager. The the sake of simplicity, each contact will have a name and a phone number only. The user should be able to create new contacts and diplay all contacts. Build a GUI using WindowBuilder and Swing.

  7. Write a very simple application for computer dictionary. The the sake of simplicity, each entry has a word and a definition. Store the pair in an ArrayList<DictEntry>. Each DictEntry has two strings. Build a GUI using WindowBuilder and Swing.

  8. Describe the system: The game of BlackJack; a single playerplays against the house for money. His bet is consistently $100.00 and he starts with 1,000.00. There is a shoe of six 52-carddecks which is reshuffled when the shoe is half used. If the playerwins the hand, his gets his bet back plus the amount of the bet. If he loses, he loses the money, and if he gets blackjack, he get's his bet * 1.5. The playerplays against a dealer who must follow the following strict rules; aces are worth 11points only, and the dealer must hit on 16 or below. The player however, is allowed to hit or hold on any hand-value. Furthermore, aces are worth either 1 or 11, whichever is more advantageous. An initial two hands are dealt on seperate sides of a table consisting of two cards apiece. The dealer's handdisplays only one card up. The player has the option to hit, hold, split, double-down, buy insurance, etc. For this initial version of the game, we'll consider only hit, hold, and deal. blue are nouns (objects or fields) red are verbs (methods)

  9. Interfaces • A class implements an interface rather than extends it. Any class that implements the interface must override all the interface methods with it's own methods. • Interface names often end with "able" to imply that they add to the capabilty of the class. • An interface is a contract; it defines the methods

More Related