Lecture No 7 Object oriented programing: Class It is a way - TopicsExpress



          

Lecture No 7 Object oriented programing: Class It is a way given by c++ to realize objects in a program. It is concrete implementation of objects in c++. We capture any object attributes and behaviour in a programming language using classes. In other words it can be defined as facility given by c++ to create new types according to our requirement. Example: Consider the examples of entity lion there are many lions but all lions will have similar attributes and behaviour. Similarly consider student object all students have separate existence but all students have similar attributes and they exhibit similar behaviour. When we hear word student or think about student a sketch comes in our mind for student along with its attributes and behaviour. The attributes of student comes in our mind are its name, roll no, class, degree so on. Similarly the behaviour of student comes in our mind are study, register and many more. We need to capture the characteristic features of any objt in the programming language. The concept of class is used for this purpose. Now consider the scenario having many interacting objects: a University System having many objects like student, subject, classroom, and teacher so on…we will realize all these objects in our software using classes. These all object will use the services of each other for example student will ask teacher to teach him. This approach is closer to real life instead of having simple functions being called from main here these objects will call each other to get their services. Uses: Objects are structured in terms of class so our problem becomes easier to understand in the terms c++ program. We can implement interactions easily in terms of classes. Student objects will interact with each other to take and give services to each other as happens in real life and mapped in object oriented programming approach. Now we see how class mechanism helps us in implementing real life concept. Type in C++: We implement generic concepts using types. We have to model generic concept of Student. But there is no built in type student in c++ like built-in c++ type’s int or float. Class is mechanism in c++ that will allow us to define student as user defined type, similarly generic concept circle will also be implemented in the same way. User define types will be, • Student in student management system • Circle in a drawing software Access specifiers: These are used to enforce access restrictions to members of a class, there are three access specifiers, 1. ‘public’ is used to tell that member can be accessed whenever you have access to the object 2. ‘private’ is used to tell that member can only be accessed from a member function 3. ‘protected’ to be discussed when we cover inheritance Clear diamond
Posted on: Thu, 24 Oct 2013 05:20:22 +0000

Trending Topics



Recently Viewed Topics




© 2015