CHAP1 - OBJECT ORIENTED PROGRAMMING.pptx

0wenraiwenbal01 20 views 25 slides Oct 11, 2024
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

A power point slide that contains an overview of the java programming language and the syntax used.


Slide Content

OBJECT ORIENTED PROGRAMMING CPE 211 - MW

Programming Paradigms: Procedural Programming - A simple step by step, line by line code of execution, linear and simple to comprehend. Object Oriented Programming - A programming paradigm based on the concept of "objects" that may contain data and procedures that is unique or shared.

Other terms used: Objects - This is the basic unit of object-oriented programming. That is both data and function that operate on data are bundled as a unit called an object. Class - A class is a blueprint you define for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. Abstraction - It refers to, providing only essential information to the outside world and hiding their background details. Encapsulation - a process of binding data members (variables, properties) and member functions (methods) into a single unit. It is also a way of restricting access to certain properties or component.

Unified Modeling Language (UML) THE UML CLASS DIAGRAM OVERVIEW

What is a UML diagram? A standardized visual modeling language used in the field of software engineering to provide a general-purpose, developmental, and intuitive way to visualize the design of a system Student Class fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) Accounts Class username :String Password :String + Accounts() + Login( usnam , pwrd ) :Boolean + Logout() : Boolean

No Duplicate names UML class diagram uses case sensitive naming to easily identify the uniqueness of the class. Student Class fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) Accounts Class username :String Password :String + Accounts() + Login( usnam , pwrd ) :Boolean + Logout() : Boolean

Inheritance The ability to create a new class from an existing class is called Inheritance. Using inheritance, we can create a Child class from a Parent class such that it inherits the properties and methods of the parent class and can have its own additional properties and methods. PARENT CLASS CHILD CLASS

Inheritance Example Student Class (Parent) fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) Accounts Class (Child) username :String Password :String + Login(username, pwrd ) : Boolean + Logout() : Boolean fullName :String IDNumber : Int Age :int + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) + Accounts ()

Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. PARENT CLASS CHILD CLASS PARENT CLASS CHILD CLASS Main Parent Child Parent

Polymorphism Example STUDENT CLASS LMS ACCOUNT CLASS LIBRARY ACCOUNT CLASS COMLAB ACCOUNT CLASS PERSON CLASS STAFF CLASS FACULTY ACCOUNT CLASS

RELATIONSHIP BETWEEN CLASS UML

Association represents a bi-directional relationship between two classes. It indicates that instances of one class are connected to instances of another class. COURSE STUDENTS

Directed Association A directed association in a UML class diagram represents a relationship between two classes where the association has a direction, indicating that one class is associated with another in a specific way. TEACHER COURSE

Aggregation a specialized form of association that represents a “whole-part” relationship. It denotes a stronger relationship where one class (the whole) contains or is composed of another class (the part). EMPLOYEES COMPANY

Composition a stronger form of aggregation, indicating a more significant ownership or dependency relationship. In composition, the part class cannot exist independently of the whole class. ENTRIES CONTACTS

Generalization (Inheritance) Inheritance represents an “is-a” relationship between classes, where one class (the subclass or child) inherits the properties and behaviors of another class (the superclass or parent) PARENT CLASS CHILD CLASS

Realization (Interface Implementation) Realization indicates that a class implements the features of an interface. It is often used in cases where a class realizes the operations defined by an interface. Phone Class Volume Interface Xiaomi Class RealMe Class

CLASS ATTRIBUTES AND FUNCTIONS

Parts of the class Name - The name of the class is typically written in the top compartment of the class box and is centered and bold. Attributes – also known as properties or fields, represent the data members of the class. They are listed in the second compartment of the class box and often include the visibility (e.g., public, private) and the data type of each attribute. Functions are actions that the class can perform. Student Class fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) Attributes Functions Name

Parts of the class Functions - also known as methods or operations, represent the behavior or functionality of the class. They are listed in the third compartment of the class box and include the visibility (e.g., public, private), return type, and parameters of each functions. Student Class fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) Attributes Functions Name

The class visibility notation Visibility notations indicate the access level of attributes and methods. Common visibility notations include: + (Public) - (Private) # (Protected) ~ (Packaged) Student Class fullName :String IDNumber : Int Age :int + Student () + GetStudentID () : Int + GetStudentName () :String + SetStudentName (Name) :Void Notation

Creating an Attribute When making an attribute for the class first you have to define its name, data type, and visibility. A Data Type can be a: String Integer Float/Double Boolean Object + myAttribute String Visibility Name Data type - myNum Int - isReal Boolean : : : - aThing Object : - myFraction Float :

Creating an Function When making an function for the class first you have to define its name, return type, parameters and visibility. A return type can be a: String Integer Float/Double Boolean Object Void + getAttribute () String Visibility Function Name Return type - setNum (int) Int - getRealCheck () Boolean : : : - setThing (Object) Object : - getFraction () Float :

Assembling the class - The assembled class would look like this as a UML Diagram. + myAttribute String Visibility Name Data type - myNum Int : : + getAttribute () String Visibility Function Name Return type - setNum (int) Int : : Some Class + myAttribute :String - myNum :Int + Some() + getAttribute () :String - setNum () :Int

GeekForGeeks : https://www.geeksforgeeks.org/unified-modeling-language-uml-class-diagrams/ TutorialsPoint : https://www.tutorialspoint.com/What-is-object-oriented-programming-OOP ExpertBeacon : https://expertbeacon.com/object-oriented-programming-principles-in-java-oop-concepts-for-beginners/ W3Schools : https://www.w3schools.com/java/java_intro.asp (Book) OOP With Java 9 th Edition . References