20 likes | 124 Views
Objects, Classes, & Methods (2.3). Computer Programming is basically the manipulation of data. How programmers manipulate data has changed from a top-down procedural programming methodology into Object Oriented Programming.
E N D
Objects, Classes, & Methods (2.3) • Computer Programming is basically the manipulation of data. How programmers manipulate data has changed from a top-down procedural programming methodology into Object Oriented Programming. • In OOP, we define real world entities as user defined types called Abstract Data Types (ADT). • ADTs are the Objects in OOP representing Real World Entities. • Bank Accounts • Employee Records • Graphical Shapes • Etc… • A Classis the mechanism we use to define an Object (ADT) in Java. • A Class has the capability to encapsulate everything an Object needs to know about itself! • Objects can contain dataand the actions or behaviors to manipulate that data. • data -> Instance Fields • behavior ->Methods ( functions that manipulate data)
Consider developing a BankAccountclass • Data (Instance Fields) -> might include – usually declared private: • balance -> myBalance • myPassword • myInterestRate • Behaviors (Methods) might include – usually declared public: • createAccount( ) • deposit( ) • withdraw( ) • viewBalance( ) • Every class has methods which can be called (invoked) by a class object (variable of a class). • Every Object belongs to a Class! • Class Variables - A class is usually stored as a separate file which is used in another program (Client Code). Class variables must be declared in-order for the Object to manipulate its data. BankAccount acct = new BankAccount( ); acct.deposit(depositAmount); • Manipulating an Objects data indirectly through public methods is referred to as Encapsulation or Data-Hiding. • We make an Objects data private to restrict direct outside access!