1.0 Introduction TO Object Oriented Programming PDF

Title 1.0 Introduction TO Object Oriented Programming
Course Computer Systems
Institution University of the People
Pages 6
File Size 210.7 KB
File Type PDF
Total Downloads 73
Total Views 135

Summary

computer science lecture notes 3...


Description

DBIT 0301/DSE 0304/DCS 0304/DIT 0301: Object Oriented Programming 1

INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

1.1 What is object-oriented programming? •

Programs are organized around data. with the key principle being "data controlling access to code."



In an object-oriented language, you define the data and the routines that are permitted to act on that data.



Thus, a data type defines precisely what sort of operations can be applied to that data.

1.2 Evolution of Object oriented Programming Programming approaches have been passing through revolutionary phases just like computer hardware. Initially for designing small and simple programs, the machine language was used. Next came the Assembly Language which was used for designing larger programs. Both machine and Assembly languages are machine dependent. Next came Procedural Programming Approach which enabled us to write larger and hundred lines of code. Then in 1970, a new programming approach called Structured Programming Approach was developed for designing medium sized programs. In 1980's the size of programs kept increasing so a new approach known as OOP was invented.

1.3 Programming paradigms A programming paradigm is a style, or “way,” of programming. Some languages make it easy to write in some paradigms but not others. Examples of programming paradigms include: 1. unstructured programming 2. procedural programming 3. modular & structured programming 4. object oriented programming

Page 1 of 6

1.3.1 Unstructured Programming In this approach, the program consists of sequence of statements that modify data. All the statements of the program are Global throughout the whole program. The program control is achieved through the use of jumps i.e. goto statements. In this approach, code is duplicated each time because there is no support for the function. Data is not fully protected as it can be accessed from any portion of the program. So this approach is useful for designing small and simple programs. The programming languages like ASSEMBLY and BASIC follow this approach.

1.3.2 Procedural programming This approach is top down approach. In this approach, a program is divided into functions that perform a specific task. Data is global and all the functions can access the global data. Program flow control is achieved through function calls and goto statements. This approach is mainly used for medium sized applications. The programming languages: FORTRAN and COBOL follow this approach. 1.3.3 Structured Programming The basic principal of structured programming approach is to divide a program in functions and modules. The use of modules and functions makes the program more comprehensible (understandable). It helps to write cleaner code and helps to maintain control over each function. This approach gives importance to functions rather than data. It focuses on the development of large software applications. The programming languages: PASCAL and C follow this approach. 1.3.4 Object Oriented Programming The OOP approach came into existence to remove the drawback of conventional approaches. The basic principal of the OOP approach is to combine both data and functions so that both can operate into a single unit. Such a unit is called an Object. This approach secures data also. Nowadays this approach is used mostly in applications. The programming languages: C++ and JAVA follow this approach. Using this approach, we can write any lengthy code.

1.4 Advantages of OOP •

Code Reuse and Recycling: Objects created for Object Oriented Programs can easily be reused in other programs.

Page 2 of 6



Encapsulation (part 1): Once an Object is created, knowledge of its implementation is not necessary for its use. In older programs, coders needed understand the details of a piece of code before using it (in this or another program).



Encapsulation (part 2): Objects have the ability to hide certain parts of themselves from programmers. This prevents programmers from tampering with values they shouldn't. Additionally, the object controls how one interacts with it, preventing other kinds of errors. For example, a programmer (or another program) cannot set the width of a window to -400.



Design Benefits: Large programs are very difficult to write. Object Oriented Programs force designers to go through an extensive planning phase, which makes for better designs with less flaws. In addition, once a program reaches a certain size, Object Oriented Programs are actually easier to program than non-Object-Oriented ones.



Software Maintenance: Programs are not disposable. Legacy code must be dealt with on a daily basis, either to be improved upon (for a new version of an exist piece of software) or made to work with newer computers and software. An Object Oriented Program is much easier to modify and maintain than a non-Object Oriented Program. So although a lot of work is spent before the program is written, less work is needed to maintain it over time.

1.5 Disadvantages of OOP •

Size: Object Oriented programs are much larger than other programs. In the early days of computing, space on hard drives, floppy drives and in memory was at a premium. Today we do not have these restrictions.



Effort: Object Oriented programs require a lot of work to create. Specifically, a great deal of planning goes into an object oriented program well before a single piece of code is ever written. Initially, this early effort was felt by many to be a waste of time. In addition, because the programs were larger (see above) coders spent more time actually writing the program.



Speed: Object Oriented programs are slower than other programs, partially because of their size. Other aspects of Object Oriented Programs also demand more system resources, thus slowing the program down.

Page 3 of 6

1.6 Operating System Requirements We can summarize the requirements in seven keywords: 1. Ease of use - Ease of use also means the hiding of unnecessary detail. Operating system aspects, for example, such as file management details, should be managed by the environment automatically, while letting the user work at a higher level of abstraction. 2. Integrated tools - integration of tools can have many benefits: A unified interface, Smaller interfaces, Increased productivity, Better functionality 3. Object-support - Classes and objects should be the main abstractions used for user-level interaction in the environment. 4. Support for code reuse -The development environment must provide a class browser for existing library classes. It should also have the ability to build new libraries of classes written. 5. Learning support - The environment must support some techniques that are known to support learning of programming concepts. Among those are: Interaction / experimentation, Visualization, 6. Group support - it is essential that the environment has some form of support for group work. 7. Availability - a system must be available at reasonable cost, and it must be able to run on commonly available hardware.

1.7 Examples of object-oriented languages Significant object-oriented languages include: Java, C++, C#, Python, PHP, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Common Lisp, and Smalltalk.

Page 4 of 6

2

OBJECT ORIENTED PROGRAMMING CONCEPTS

2.1 Basic Object-Oriented concept 2.1.1 What is class? Class is a collection of similar types of objects, where each class having similar properties and types. Ex: Bird, Animal 2.1.2 Need of class and object Class supports data encapsulation and data abstraction which leads C++ a more secure programming language. Apart from these features, the class also has private and public section, where we put the very important data in private section and comparatively less important data in public section. These two are known as access specifiers.

2.2 Features of OOPS The main features of OOP are class, object, data hiding and encapsulation, inheritance, polymorphism and message passing. 2.2.1 Class and Object Class is a collection of similar types of objects. For example if college, school, institutions are three objects then combine the three objects to form a class and the class name is Education. Ex2: If elephants, tigers, lions and cats will be considered as objects then the class for these objects will be Animal. You can consider the class and object name as per your wish and always keep in mind that these objects are formed from the class. So, class is imagined as a whole and objects are part of it. 2.2.2 Data hiding Putting the data in private section can only be accessed by using object and the function associated with it. This feature of OOP is known as data hiding.

Page 5 of 6

2.2.3 Encapsulation Wrapping around data and functions inside a class is known as encapsulation. This feature makes program easy to understand. 2.2.4 Inheritance The code reusability features for programming which is also known as inheritance. So, inheritance is the property by which one class can get the properties of another class. 2.2.5 Polymorphism Poly means many and morphism means form. It’s a Greek word whose meaning is one name multiple form. This feature allows to write same name for functions and operators but the meaning for each one varies in different places. It’s of two types i.e. runtime polymorphism and compile time polymorphism. 2.2.6 Dynamic binding Associating function call during program execution is known as dynamic binding. 2.2.7 Message passing Objects communicates with each other through message is known as message passing. Data is transferred from one object to another through object and functions. Note: Most frequently variables are put in private sections because these are very sensitive data for the real-world purpose. Generally, functions are put in public section which are mainly used for accessing these private data.

Page 6 of 6...


Similar Free PDFs