Summary

This PowerPoint presentation introduces object-oriented programming (OOP) concepts, specifically focusing on abstraction, classes, and objects. It explains the role of classes as blueprints for objects, the characteristics of objects, and how objects communicate using methods. The presentation also provides examples, including employee and car objects, and shows how to define a class in C#.

Full Transcript

Introduction to OOP Week 2 ABSTRAC TION: CLASSES AND OBJECTS Classes: Classes are the main focus in Object oriented programming (OOP).  A class is like a blueprint of a specific object.  A class is a collection of objects of similar type.  A...

Introduction to OOP Week 2 ABSTRAC TION: CLASSES AND OBJECTS Classes: Classes are the main focus in Object oriented programming (OOP).  A class is like a blueprint of a specific object.  A class is a collection of objects of similar type.  A class is a model for creating objects. Objects: an instance of a class, and the process of creating an object is called instantiation.  What that means is that ⇒ an Object is an actual physical existence of a Class. It is a real entity whose structure, identity and behavior are decided by a Class.  An object is a block of memory that has been allocated and configured according to the blueprint.  Blueprint: An object is a combination of data/fields and methods.  Fields are actual variables in your object that stores a particular piece of information.  The data and the methods are called members of an object.  These objects communicate together through methods - actions they perform.  Each object can receive messages, send messages and process data.  A program may create many objects of the same class.  Objects are also called instances, and they can be stored in either a named variable or in an array or collection  Creating an object means allocating memory to store the data of variables temporarily. i.e. we create an object of class to store data temporarily. Examples If a class can be defined as a template/blueprint that describes the behavior/state that an object of its type support - what does this mean?  If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc.  All these objects have a state and a behavior.  If we consider a dog, then its state or characteristics/attributes include - name, breed, color.  If we consider a dog, then its behavior is - barking, wagging the tail, running  If we consider an Employee: the state/fields/ characteristics/attributes include Name, Id, Salary etc respectively.  If we consider a Car as a class then examples of objects of this car include Toyota, Nissan, Audi, Golf etc  If we consider a Car as a class then: state/fields/ characteristics/attributes include wheels, doors, seating capacity.  If we consider a Car as a class then its behavior is: accelerate, stop, display how much fuel is left etc. Consider the following code to demonstrate how to define a class namespace ProductMaintenance { public class Product { private string code; private string description; private decimal price; public Product(){} public Product(string code, string description, decimal price) In short, a class has: Accessibility level - please visit INF1003. Class name Fields: actual variables in your object that stores a particular piece of information, Properties and Methods/ functions Summary on classes Software objects have a state and a behavior. A software object's state is stored in fields and behavior is shown via methods. Methods operate on the internal state of an object and the object-to-object communication is done via methods. A good rule of thumb to identify classes in Object Oriented programming is that: Classes are the Nouns in your analysis of the problem Methods in an class correspond to the Verbs that the noun does Properties are the Adjectives that describe the noun ABSTRAC TION: CLASSES AND Abstraction OBJECTS  Abstraction is a principle of object-oriented programming language (OOP)  The word abstract means a concept or an idea not associated with any specific instance  It is used to hide the implementation details and display only essential features of the object. i.e allows making relevant information visible ABSTRAC TION: CLASSES Abstraction AND  It is a process of abstracting or hiding the functionality.....making classes not associated with any OBJECTS specific instance ~object  eg: for the method Console.WriteLine(), no one knows what actually is happening behind the function calling. We are just using it by calling and passing the arguments. This is the thing called Abstraction.  Abstraction is needed when we need to only inherit from a certain class, but do not need to instantiate objects of that class. In such a case the base class can be regarded as "Incomplete". Such classes are known as an "Abstract How to implement abstraction in c#  Use the keyword Abstract ABSTRAC TION: CLASSES AND OBJECTS  Once a class has been declared as an Abstract class, it cannot be instantiated; it means the object of that class cannot be created.

Use Quizgecko on...
Browser
Browser