plus 2 presentation 2

Information about plus 2 presentation 2

Published on July 11, 2014

Author: libiya

Source: authorstream.com

Content

PowerPoint Presentation: COMPUTER SCIENCE PLUS 2 CHAPTER 6 BY LIBIYA JOSE PowerPoint Presentation: Programming Paradigm --- defines the methodology of designing and implementing programmes using key features & building blocks of a language ---- gives us an idea how problems are generally analyzed & solved in a particular language. PowerPoint Presentation: Three types of Programming paradigm Procedural Programming paradigm Object based Programming paradigm Object oriented Programming paradigm PowerPoint Presentation: Procedural Programming paradigm emphasis on procedure than data e.g. C and C++ also uses this style with some enhanced features such as type checking , inline functions PowerPoint Presentation: Procedural Programming paradigm ( contd …) Separates functions and data Leads to problems when extending or maintaining the software Whenever the definition of a type changes the functions referring to this type must also be changed to reflect the change. Is susceptible to design changes Leads to increased time & cost overheads during the design changes. PowerPoint Presentation: Eg ; struct student { int rollno ; }; void readstudent (student s1) { cout << “enter roll number”; cin >> s1.rollno; } Now suppose due to change in the design, student structure has to hold marks and grade as well that is structure now modifies to struct student { int rollno ; float marks; Char grade; }; Now all the functions working on structure must also b modified. Thus readstudent () must also be modified to cope with the change in structure. PowerPoint Presentation: 2 . Object based implements some features of OOP Data & its functions are enclosed in one single entity called class Classes enforce Information Hiding & Abstraction thereby separating the implementation details and the user interface PowerPoint Presentation: Object based ( contd …) eg . Calculator its interfaces are screen & buttons, are available to user but implementation details are hidden ie , users of a class are allowed to access its interface but they cannot access its implementation details. ie , OBP localizes the implementation details It is subset of OOP PowerPoint Presentation: Eg ; Class student { int rollno ; char name[25]; int clas ; float marks; Public: void readstudent (); void dispstudent (); } This remains hidden This makes user interface PowerPoint Presentation: Class student { int rollno ; char name[25]; int clas ; float marks; Char grade; Public: void readstudent (); void dispstudent (); } Changes have occurred in hidden part User interface remains same PowerPoint Presentation: When changes occur in hidden part, user interface remains same . Now users would not know that a new field has been added. Because the change is localized to the definition of the changed function Subset of OOP bcz it does not implement inheritance & thereby polymorphism. PowerPoint Presentation: Adv of OBP Overcomes the shortcomings of procedural Localizes changes & Hides implementation details Supports user defined types Implements abstraction and information hiding Limitations of OBP Its inability to represent real world relationship that exist among object. e.g.; car & Truck are vehicles but cannot be implemented by OBP as it does not support inheritance. PowerPoint Presentation: Object oriented Programming paradigm Implements inheritance Real world relationships can be represented programmatically is superset of OBP PowerPoint Presentation: 11-Jul-14 Basic Object-Oriented Concepts Basic Object-Oriented Concepts OOP Concept: 15 OOP Concept Every object belongs to (is an instance of) a class An object may have fields , or variables The class describes those fields An object may have methods The class describes those methods An object contains both data and methods that manipulate that data The data represent the state of the object Data can also describe the relationships between this object and other objects PowerPoint Presentation: Object is an identifiable entity with some characters & behaviour Represents an entity that can store data and has its interface through functions. In OOP Views every problem in terms of Objects involved rather than procedure for doing it. Eg : Baking using oven Ovens are used to make a lot of diff dishes. We don’t want to create a new oven every time we encounter a new recipe. Having solved a problem once it would be nice to be able to reuse the solution in future programs. This is not only reduces software cost but also results in simpler program design. PowerPoint Presentation: Another eg ; Orange is an object . It’s characters are: Spherical shaped & colour is orange It’s Behaviour is : juicy , tastes sweet – sour While Programming , Characters are represented by its data & Behaviour is represented by its functions associated. PowerPoint Presentation: ‘Object’ is an instance of ‘class’ Eg : bird is a class. parrot is an object , sparrow is another object Class : is a group of objects that share common properties and relationships. that is class is actually representation of char and behavior of same category of objects. PowerPoint Presentation: Function 1 Fn 2 Fn 3 Data 2 Data 1 Properties __________ Behaviour Properties __________ Behaviour Object 1 Object 2 All data is openly available to all functions in the program Conceptual difference b/w procedural paradigm and OO paradigm Key features of OOP Concepts: Key features of OOP Concepts Data encapsulation or Information Hiding Data abstraction Inheritance Polymorphism Modularity PowerPoint Presentation: Data Abstraction Abstraction means simplifying a real world concept into its essential elements Eg . Car : wt is happening is hidden from u. Thia is abstraction here we know the essential things to drive a car without including background details. Background details are hidden from u. PowerPoint Presentation: Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details. The concept of abstraction relates to the idea of hiding data that are not needed for presentation. The main idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details. PowerPoint Presentation: An Abstract Data Type is defined as a data type that is defined in terms of the operations that it supports and not in terms of its structure or implementation.  Since classes uses the concept of data abstraction , they are known as ADT. Data types bcz these can b used to create objects of its own type. PowerPoint Presentation: Data encapsulation : way of combing both data &the fns that operate on that data under a single unit. That is wrapping up of data and fns / operations into ma single unit. Member fns : are fns that provide the way to access data. The data cannot be accessed directly. Data encapsulation Data hiding is the implementation details of a class that are hidden from the user. PowerPoint Presentation: Data Encapsulation: Data Encapsulation combines data and functions into a single unit called class. Data Encapsulation enables the important concept of data hiding possible. Encapsulation is the process of combining data and functions into a single unit called class. Data is only accessible through the functions present inside the class. PowerPoint Presentation: Object DATA MF Object DATA MF Object DATA MF combines data and functions into a single unit PowerPoint Presentation: class MyClass { public: int sample(); int endfunc (); .. //Other member functions private: int x; float sq; ..... //Other data members }; In the above example, the data members integer x, float sq and other data members and member functions sample(), endfunc () and other member functions are bundled and put inside a single autonomous entity called class MyClass . This exemplifies the concept of Encapsulation. PowerPoint Presentation: Encapsulation alone is a powerful feature that leads to information hiding, abstract data type and friend functions. Abstraction & Encapsulation ar e complementary concepts Focuses upon the implementation Focuses upon the observable behaviour Achieved through Inf. Hiding PowerPoint Presentation: Encapsulation is basically to bind data members & member functions into a single unit called Class. Whereas Abstraction is basically to hide complexity of implementation & provide ease of access to the users . Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world . Abstraction refers to showing only the necessary details to the intended user. As the name suggests, abstraction is the " abstract form of anything". We use abstraction in programming languages to make abstract class. Abstract class represents abstract view of methods and properties of class. PowerPoint Presentation: Abstraction represent taking out the behavior from How exactly its implemented Abstraction is implemented using interface and abstract class while Encapsulation is implemented using private and protected access modifier. Abstraction is implemented using interface and abstract class while Encapsulation is implemented using private , public and protected access modifiers. Encapsulation is also called data hiding. PowerPoint Presentation: Modularity Partitioning a pgm into individual components a module is a separate unit in itself It can b compiled separately Modules work hand in hand in order to achieve the program’s goal Justification for partitioning a pgm is that It reduces its complexity to some degree It creates no.of well defined , documented boundaries within the pgm eg ; music system speaker , cassette player, record player , cd player,tuner etc are complete units in themselves , yet they are a sub part of a music system PowerPoint Presentation: Modularity( contd …) In OO lang , classes & objects form the logical structure of a system. we place them in modules to produce the system’s physical architecture Modules are essential to manage complexity especially for larger applications eg ; iostream.h ------------ .h suffix is used to place module interface and the pgm files that depend upon header files can use them through #include directive PowerPoint Presentation: Inheritance INHERITANCE Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class. For eg ; Vehicles Automobile pulled vehicles car bus Cart rickshaw PowerPoint Presentation: Features or Advantages of Inheritance: Reusability: Inheritance helps the code to be reused in many situations. The base class is defined and once it is compiled, it need not be reworked. Using the concept of inheritance, the programmer can create as many derived classes from the base class as needed while adding specific features to each derived class as needed. Saves Time and Effort: The main code written can be reused in various situations as needed. PowerPoint Presentation: Why Inheritance ? To ensure the closeness with real-world models Reusability : reduces the amount of typing and efforts one reason is the transitive nature . For instance Person Student //subclass of person Graduatestudent //subclass of student That is graduatestudent is also be a person Thst is inheritance is trasitive . PowerPoint Presentation: Polymorphism: Poly means many and morphs mean form, so polymorphism means one name multiple form. There are two types of polymorphism: compile time and run time polymorphism. Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways. Concept: Classes form a hierarchy: 38 Concept: Classes form a hierarchy Classes are arranged in a treelike structure called a hierarchy The class at the root is named Object Every class, except Object , has a superclass A class may have several ancestors, up to Object When you define a class, you specify its superclass If you don’t specify a superclass , Object is assumed Every class may have one or more subclasses PowerPoint Presentation: In C++ an object may have more than one parent (immediate superclass ) but not in Java! Concept: Objects inherit from superclasses: 40 Concept: Objects inherit from superclasses A class describes fields and methods Objects of that class have those fields and methods But an object also inherits : the fields described in the class's superclasses the methods described in the class's superclasses A class is not a complete description of its objects! Concept: Objects must be created: 41 Concept: Objects must be created int n; does two things: It declares that n is an integer variable It allocates space to hold a value for n For a primitive, this is all that is needed Employee secretary; also does two things It declares that secretary is type Employee It allocates space to hold a reference to an Employee For an object, this is not all that is needed secretary = new Employee ( ); This allocate space to hold a value for the Employee Until you do this, the Employee is null Notation: How to declare and create objects: 42 Notation: How to declare and create objects Employee secretary; // declares secretary secretary = new Employee (); // allocates space Employee secretary = new Employee(); // does both But the secretary is still "blank" ( null ) secretary.name = "Adele"; // dot notation secretary.birthday (); // sends a message Notation: How to reference a field or method: 43 Notation: How to reference a field or method Inside a class, no dots are necessary class Person { ... age = age + 1; ...} Outside a class, you need to say which object you are talking to if (john.age < 75) john.birthday (); If you don't have an object, you cannot use its fields or methods! Concept: A variable can hold subclass objects: 44 Concept: A variable can hold subclass objects Suppose B is a subclass of A A objects can be assigned to A variables B objects can be assigned to B variables B objects can be assigned to A variables, but A objects can not be assigned to B variables Every B is also an A but not every A is a B You can cast : bVariable = (B) aObject; In this case, Java does a runtime check

Related presentations