🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

6OOP - Prelim Week 1 and 2 Lecture.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Week 1 and 2 Objectives  Compare procedural and object- oriented programming  Learn about classes and objects  Create a class  Create instance methods in a class  Declare objects and use their methods 3 Comparing Procedural and Object-Oriented Pro...

Week 1 and 2 Objectives  Compare procedural and object- oriented programming  Learn about classes and objects  Create a class  Create instance methods in a class  Declare objects and use their methods 3 Comparing Procedural and Object-Oriented Programming Concepts  Procedural programming  Sets of operations executed in sequence  Variables  Named computer memory locations that hold values  Procedures  Individual operations grouped into logical units  Object-oriented programs  Create classes  Blueprints for an object  Create objects from classes  Create applications 4 Comparing Procedural and Object-Oriented Programming Concepts (cont’d.)  Object-oriented programming was used most frequently for two major types of applications  Computer simulations  Graphical user interfaces (GUIs)  Not all object-oriented programs are written to use a GUI  Object-oriented programming differs from traditional procedural programming  Polymorphism  Inheritance  Encapsulation 5 Class Understanding Describes objects with common properties A definition Classes, An instance Objects, and Attributes Encapsulation Characteristics that define an object Differentiate objects of the same class The value of attributes is an object’s state Objects Specific, concrete instances of a class 6 Understanding Classes, Objects, and Encapsulation (cont’d.) 7  Method  A self-contained block of program code that Understanding carries out an action  Similar to a procedure Classes,  Encapsulation Objects, and  Conceals internal values and methods from outside sources Encapsulation  Provides security  Keeps data and methods safe from (cont’d.) inadvertent changes 8 Conceals internal values and methods from outside sources Encapsulation Provides security Keeps data and methods safe from inadvertent changes  Inheritance An important feature of Understanding object-oriented programs Inheritance and  Polymorphism Polymorphism Means “many forms” 10 Inheritance  Classes share attributes and methods of existing classes but with more specific features  Helps you understand real-world objects Polymorphism Means “many forms” Allows the same word to be interpreted correctly in different situations based on context Learning About Classes and Objects  Every object is a member of a class  Is-a relationships  An object “is a” concrete example of the class  The zoo’s shark “is a” Fish  Instantiation  Shark is an instantiation of the Fish class  Reusability 13 Learning  Methods are often called upon to return a piece of information to the About Classes source of the request  Class client or class user and Objects  An application or a class that instantiates objects of another (cont’d.) prewritten class 14 Assign a name to the class Creating a Determine what data and methods will be Class part of the class Create a class header with three parts: An optional access modifier The keyword class Any legal identifier for the name of the class public class Accessible by all objects 15 Creating a Class (cont’d.) Instance Extended Data fields variables To be used as a Variables Nonstatic fields basis for any declared within given to each other class a class but object outside of any method 16 Creating a Class (cont’d.)  Private access for fields  No other classes can access the field’s values  Only methods of the same class are allowed to use private variables  Information hiding  Most class methods are public 17  Classes contain methods  Mutator methods Set or change field values Creating  Accessor methods Retrieve values Instance  Nonstatic methods Methods in a Instance methods “Belong” to objects Class  Typically declare nonstatic data fields  static class variables are not instance variables 18 Static and Nonstatic Creating Instance Methods in a Class (cont’d.)  Place data fields in logical order  At the beginning of a class  List the fields vertically Organizing  Data fields and methods may be placed in any order within a class Classes  It’s common to list all data fields first  Names and data types can be seen before reading the methods that use the data fields Organizing Classes (cont’d.) Organizing Classes (cont’d.) QUESTIONS? 25

Use Quizgecko on...
Browser
Browser