Download Object-Oriented Programming: A Practical Introduction with Java using BlueJ and more Study Guides, Projects, Research Information Technology in PDF only on Docsity! 1 Object-Oriented Programming 04:547:202 (02) Instructor: Gheorghe Muresan Based on: Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling 1.0 2 Course Contents • Introduction to object-oriented programming… • …with a strong software engineering foundation… • …aimed at solving problems by producing and maintaining high-quality software systems. 2 3 Goals • Sound knowledge of programming principles and concepts • Sound knowledge of object-orientation • Able to critically assess the quality of a (small) software system • Able to implement a small software system in Java Note. Understanding principles is more important than learning Java syntax, so that, in the future, you can use other programming languages. 4 What is programming • Narrow definition – Using some programming language to write code, based on some specification • Boring, nerdy • Broader definition – Using creative thinking and engineering rigor to solve problems using the computer • Involves analyzing a situation, designing a solution, choosing the appropriate language and coding the solution, testing • It is exciting, challenging and … HARD 5 9 Non-IT careers using IT • Research in cutting-edge areas – Genomics, Pharmaceuticals – Nanotechnology – Nuclear Physics, Cosmology – Weather simulation – Information retrieval Most of these researchers need programming; they learn it out of pleasure or necessity • Almost anything, to a certain extent 10 Is math a pre-requisite for IT ? • No, math background is not a pre- requisite, but it is useful • Ability to think in abstract terms and to build models • Different math areas can help in certain types of problems (ex: geometry & trigonometry for graphical applications, statistics in search engines) 6 11 Model • A (usually simplified) representation of the problem • Consists of – a data structure (for primary and derived data) – formulae and rules – context – assumptions • Model vs. view • Problems with similar models have similar solutions – Often code can be re-used; don’t re-use code blindly, understand the conceptual model and the constraints ! 12 Homework • Use Excel to build models for: – A TV show: you start with $50 and throw 2 dice; if you throw a double, you get $10, otherwise you lose $1; you’re out if you run out of money or if you reach $75. – A game on the stairs of the Olympic Stadium in Athens: you start on step 30 (out of 99) and throw a dye. If you throw a 5 or a 6, you move 12 steps up, otherwise 1 step down. You’re out when you reach the top or bottom of the stairs. Place it in Homeworks/HW1/, in 202. 7 13 Problem solving (Polya applied) • Understand the problem • Devise a plan for solving the problem – Think how an algorithmic procedure might solve the problem • Carry out the plan – Formulate the algorithm and represent it as a problem • Evaluate the solution for accuracy and for its potential as a tool for solving other problems Note. Reading and understanding other people’s programs is good training for programming. 14 Complex problem solving • Goals, objectives – What are the tasks you are trying to achieve ? • Divide and conquer – Is the problem too large to grasp ? Can it be broken into smaller problems ? Can the solutions to the smaller problems be assembled to give the overall solution ? • Ex: Planning to climb Everest with a group of friends. What do you need to arrange ? – Finance (savings or sponsorship); training (fitness, high altitude survival, ice-climbing technique); timing; visas, permits and guides; equipment, clothing and food; medical considerations; safety issues 10 19 Elements of software design • When designing a program think of – The main purpose of the program – The tasks and subtasks that make up the object of the program – Decide what paradigm and what programming language is more appropriate • Ex: Perl good for text processing, COBOL for financial applications, FORTRAN for mathematical calculations, C++ for large projects that require efficiency, Java for multi-platform distributed applications, … • Think of cost, availability of tools and skills, maintenance, … – Think of possible future extension of the program and design accordingly 20 Dealing with complexity • Reminder: a program models reality and attempts to solve a problem or to undertake a task • Humans have different ways of dealing with complexity – Divide and conquer – split complex tasks into smaller and more simple ones – Team-working – assign different tasks, at various levels of complexity, to teams and individuals • Each team or person is responsible for making sure that their task was completed; they report results or errors • There has to be some higher level of control that assign tasks, puts results together, and is responsible for the overall task 11 21 Object-oriented software engineering • Object-oriented software engineering (analysis, design, programming & testing) attempts to simulate – The real problem domain • Objects and classes in the software application correspond to objects and concepts in the real world (Account, Bank, Customer, …, in a financial application) – The way people work on projects or to solve problems • For small problems, one person may be able to do all the work • Larger problems / projects require teamwork; each person specializes for a certain task or aspect of the problem and plays a role; people need to communicate, to exchange information and to synchronized their activities; their work is coordinated by managers • Objects and classes correspond to people and roles 22 Object-oriented software engineering • A software project is similar to a company in terms of structure and functionality – There is a public class that represents the CEO and has ultimate control and responsibility – Tiny programs (contractors) consist of one class with a main role (method) – Small programs (companies) consist of one class (person) with several methods, one for each role (function) – Medium programs (companies) consist of several classes (people) that interact. One is the CEO. – Large programs (companies) consist of many classes (people), grouped in packages (departments); each package specializes in some aspect of the overall job; objects of each class specialize in specific tasks 12 23 Teaching / learning programming • Vocabulary • Grammar / syntax • Jargon, phrasal verbs, common expressions • Conversation • Patterns of language use – what to write in a resume, what to say in a job interview – how to behave in various situations • Think of Java (or any other programming language) simply as a new foreign language – What should you learn first ? 24 Learning programming • Traditional programming textbooks teach the elements of the language sequentially – Adv: The students builds on what was taught earlier – Disadv: It can be dry and boring to start with, and students lose interest • Modern approach – start with the essential concepts and realistic applications, iterate often to fix the concepts – Adv: It is more interesting, students learn what is essential – Disadv:Some guesswork and trust is necessary