0% found this document useful (0 votes)
32 views

Thinking in Objects - Programming Principles & Design Methodologies

Uploaded by

bababoi4579
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views

Thinking in Objects - Programming Principles & Design Methodologies

Uploaded by

bababoi4579
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
Q Penseum inking in Obj * Away of making programs. * Centers around information. * Emulates how the real world is built. * Programs are made of things. Explain the object-oriented design methodology as a way of making programs. Define the starting question of the programming process. Explain the Object-Oriented Analysis (OA) process, its purpose, and outcome. Identify objects a program is made of by analyzing the requirements of simple programs. Explain the need to categorize objects into classes. Design Methodologies * Centered around information. * An engineering view of a program. * Emulates how the real world is built. * Programs are made of things. Object-Oriented Design * Centered around information. * Emulates how the real world is built. * Programs are made of things. # Introduction to Programming Principles Overview * Programming is the process of creating computer programs to solve problems and perform tasks. * Programs are built using methods and algorithms to transform information. * Python is an object-oriented programming language that supports other paradigms as well. Object-Oriented Design/Programming * Object-oriented programming is a programming paradigm that organizes data and functions into objects * Objects are instances of classes and represent real-world entities. * Object-oriented design focuses on creating classes and objects to model real-world concepts. ‘Structured Design * Structured design is an approach to designing programs that emphasizes breaking down a problem into smaller, manageable modules. “ Itinvolves creating clear and organized structures for program flow and data organization. The Eitst Question * The first question in software development is understanding what the program needs to do. * This involves analyzing the requirements and defining the problem to be solved * Itis important to have a clear understanding of the desired outcome before starting the design and implementation process. Exercise 1: The Real World "In this exercise, we are asked to think about what a typical classroom is made of. * We are instructed to make a list of things that a classroom is made of. * After making the list, we are paired up with another student to discuss our findings through chat. * Finally, we are asked to share our answer on a shared whiteboard, being careful not to overwrite existing text. Software Development Activities Requirements Analysis and Definition: * This activity involves understanding and documenting what the program needs to do. * Itincludes gathering requirements from stakeholders and defining the problem to be solved. Design: * The design phase focuses on creating a plan for how the program will be structured and organized. Itincludes creating diagrams, flowcharts, and other visual representations of the program's structure. Implementation and Testing: * Implementation involves writing the actual code for the program based on the design. “Testing is done to ensure that the program functions correctly and meets the requirements. Maintenance: * Once the program is implemented and tested, it may require ongoing maintenance and updates. This includes fixing bugs, adding new features, and improving performance. By following these software development activities, we can effectively create programs that meet the desired requirements and solve problems efficiently. # Main Topic: Program Design and Functionality ‘Subtopic 1; Functional Requirements * Requirements are functional * Users need functionality * Users provide input on what they need * Software engineers determine what the application needs to do * Software systems are specified in terms of functions * Functional requirements define what the application is supposed to do * End result is a list of functions ‘Subtopic.2: Program Design * The design of a program determines its composition * Design is like a blueprint for the program * Designing comes before programming * Object-Oriented Design is commonly used * Object-Oriented Design models the application after the real world * Real-world objects are represented in the program ‘Subtopic 3: Object-Oriented Design * Object-Oriented Design aims to emulate the real world * Objects in the real world are represented in the program * Objects have attributes and behaviors * Objects interact with each other through methods * Object-Oriented Design helps create a virtual world similar to the real world # Object-Oriented Analysis (00A) Object-Oriented Analysis is the process of analyzing the functionality of @ program to identify the objects that perform it. Itinvolves carefully reading and analyzing the requirements to understand what the program does from an object-oriented perspective. ‘Steps in Object-Oriented Analysis Read and analyze the requirements: The first step in OOA is to carefully read and analyze the requirements of the program. This involves understanding what the program is supposed to do and identifying the actions or functionality that needs to be performed. Identify the objects: Once the requirements have been analyzed, the next step is to identify the objects that perform the functionality. Objects are the entities in a program that have properties (data) and functionality (methods). By analyzing the requirements, we can determine the objects that are needed to fulfill the program's functionality. Analyze from an object-oriented perspective: During the analysis, it is important to approach the requirements from an object-oriented perspective. This means considering how the objects interact with each other and how they can be organized to achieve the desired functionality. It also involves considering the relationships between objects and any inheritance or polymorphism that may be required By following these steps, we can effectively analyze the functionality of a program and identify the, objects that will be used in the design and implementation Example: Lets consider a requirement for a banking system. The requirement states that the system should allow customers to create accounts, deposit money, withdraw money, and check their account balance Read and analyze the requirements: We understand that the program needs to have functionality related to banking operations such as account creation, deposit, withdrawal, and balance checking. Identify the objects: Based on the requirements, we can identify the following objects: * Customer: Represents a customer of the bank. * Account: Represents a bank account. * Transaction: Represents a transaction made by a customer (€.g., deposit or withdrawal). Analyze from an object-oriented perspective: We can consider how these objects interact with each other. For example, a customer can have multiple accounts, and each account can have multiple transactions. We can also consider any inheritance or polymorphism that may be required, such as different types of accounts (e.g., savings account, checking account), By performing object-oriented analysis, we can identify the objects needed for the banking system and understand how they relate to each other to fulfill the program's functionality. # Object-Oriented Analysis (00A) ‘Step 1: Finding the Objects * The first step in OOA is to identify the objects in a program. * Objects can be thought of as the "nouns" in the program. “To find the objects, we read the requirements and identify all the nouns. * Nouns in the program represent the objects. * Finding the objacts helps us understand the real-world entities that the program is emulating, Example: Finding Nouns * Consider the sentence: "The driver took the car to the dealership.” * The nouns in this sentence are: driver, car, dealership. “These nouns represent the objects in the program. * Similarly, in the sentence "John took his car to the dealership’ the nouns are: John, car, dealership. * By identifying the nouns, we can find the objects in the program. ‘Step 2: Finding the Relationships between Objects * Once we have identified the objects, the next step is to find the relationships between them. * Relationships describe how objects interact with each other. * Relationships can be represented using various techniques such as associations, aggregations, and compositions. ‘Step 3: Finding the Methods (Functionality) the Objects Have * After identifying the objects and their relationships, we need to determine the functionality or methods that the objects have. * Methods represent the actions or behaviors that objects can perform. * Methods can be thought of as the "verbs" in the program. * By identifying the methods, we can understand how objects interact and what actions they can perform Example: Finding Methods * Consider the sentence: "Mary has a motorcycle so she can get to work fast through traffic” “The methods or actions in this sentence are: has, get to work fast through traffic. * These methods represent the functionality of the object "motorcycle." * Similarly, in the sentence "A car would slow her down," the method is: slow her down * By identifying the methods, we can determine the actions that objects can perform In summary, object-oriented analysis involves three steps’ finding the objects, finding the relationships between objects, and finding the methods or functionality that objects have. By following these steps, we can gain a better understanding of the program and how objects interact with each other. # Object-Oriented Analysis ‘Step 1: Analyzing Program Requirements The program requirements for the guessing game application are as follows: * Create an application where 3 players can play a guessing game. “The application shall randomly choose a number between 0 and 9. “The 3 players, which are automatically created by the game, shall randomly guess @ number between 0 and 9. * The first player to guess correctly wins. * Each player shall be identified as an object in the program. Based on these requirements, the following objects can be identified: Game: Represents the overall game and manages the gameplay. Player: Represents « player in the game. NumberGenerator: Generates a random number between 0 and 9 for the game. Guess: Represents a player's guess for the number. Winner: Represents the player who guesses correctly and wins the game. ‘Step 2: Identifying Objects To identify objects, we need to look for nouns in the requirements. Here are the identified objects: * Application * Players “Number “Game * Guess. * Winner ‘Step 3: Pairing and Sharing Pair up with a student and discuss your findings. Write your answer on the shared whiteboard without overwriting existing text. Remember to consider the nouns in the requirements and think about the different entitias involved in the game Example of sharing on the whiteboard * Application * Players * Number “Game “Guess * Winner # Object-Oriented Analysis Program Requirements * Create an application where 3 players can play a guessing game. * The application shall randomly choose a number between 0 and 9. The 3 players, Larry, Curly, and Moe, shall be automatically created by the game. * Each player shall randomly guess a number between 0 and 9 * The first player to guess correctly wins, * The program shall show the guess of each player, who won, and in how many rounds. Next Step in Object-Oriented Analysis * After identifying the list of objects, the next step is to define the classes and their attributes and behaviors * Classes are used to create objects, which are instances of those classes. “Each class represents a concept or entity in the problem domain * Attributes are the characteristics or properties of an object. * Behaviors are the actions or operations that an object can perform References * Think Python: How To Think like a Computer Scientist, Chapter 15: Classes and objects * Head First Programming, Chapter 6: Modular Programming * Learning Python, [specific chapter not provided] # Main Topic: Object-Oriented Programming Chapter 22: Modules the Big Picture * Modules are a way to organize and reuse code in Python * They allow us to break our program into smaller, more manageable pieces. * Modules can contain functions, classes, and variables. * We can import modules into our program to use their functionality. Chapter 2: Module Coding Basics * In this chapter, we learn the basics of creating and using modules in Python. * We learn how to define functions and classes in a module. * We learn how to import a module and use its functions and classes in our program. Chapter 26: OOP: The Big Picture * Object-Oriented Programming (OOP) is a programming paradigm that focuses on objects and their interactions. * 00P allows us to model real-world entities as objects and define their behavior through classes. * OOP provides concepts like encapsulation, inheritance, and polymorphism to organize and structure our code, Chapter 27: Class Coding Basics * Classes are the building blocks of object-oriented programming. * Aclass is a blueprint for creating objects with similar properties and behaviors. * We define a class using the class keyword and give it a name. * Inside a class, we can define attributes (variables) and methods (functions) that describe the behavior of objects created from the class. Chapter 28: A More Realistic Example “In this chapter, we explore a more realistic example of using classes in Python. * We create a class to represent a car and define attributes and methods related to cars. * We learn how to create objects from the class and use their attributes and methods. Chapter 29: Class Coding Details * This chapter dives deeper into the details of coding classes in Python. * We learn about constructor methods (__init__) and how to initialize object attributes. * We learn about instance variables and class variables. * We also learn about inheritance and how to create subclasses that inherit attributes and methods from a parent class. Learning Outcomes Explain the need for categorizing objects into classes Identify classes of objects using rudimentary object-oriented design guidelines Contrast object-oriented analysis with object-oriented design activities. Analyze the class declaration and definition syntax in Python. Create programs made of multiple classes using the Python programming language. * In this # Main Topic: Programming Principles eieania , During the analysis phase of programming, there may be a tendency to identify too many objects. However, not all of these objects will be necessary in the final program. Some objects may be duplications or have different names for the same concept. Additionally, some analysis objects may not end up being objects in the final application at all. * Abstraction vs. Concrete: When dealing with 4 large amount of information, abstraction allows us to focus on the general case that covers many detailed cases. Abstraction is a way of generalizing objects. * Abstraction = Generalization: By abstracting objects, we can create a more generalized representation that encompasses multiple specific cases. ‘Subtopic 2: Classes Classes are templates used for defining, creating, and managing objects in programming. * Aclass serves as a blueprint for creating objects. It defines the properties and behaviors that objects of that class will have, * By creating a class, we can easily create multiple instances of objects with similar characteristics. * Classes allow for code reusability and organization. They help in structuring the program and separating different functionalities into distinct units. * Example: If we have a class called "Car’, we can create multiple car objects based on that class, each with its own unique properties such as color, model, and speed ‘Subtopic 3: Abstraction Abstraction is a concept in programming that allows us to focus on the essential features of an object or system while ignoring unnecessary details. * Abstraction helps in simplifying complex systems by breaking them down into manageable and understandable components. * Itallows us to create generalized representations that can be used to solve a wide range of problems. * Example: When designing a game, we can abstract the concept of a “player” by defining its essential properties and behaviors, such as position, health, and movement. The specific details of the player, such as the character's appearance or abilities, can be abstracted away for the sake of simplicity and reusability. >uptopic 4: Generalization Generalization is the process of creating a more generalized representation of objects or concepts * Itinvolves identifying common characteristics and behaviors among different objects and combining them into a more abstract representation. * Generalization helps in reducing redundancy and improving code efficiency by allowing us to reuse common functionalities. * Example: In a banking application, we can generalize the concept of an "account # Using Objects Template * A template is a blueprint or a recipe for creating objects. “It defines the common structure and behavior of objects of a certain type. ‘Common Name * Objects of the same type are referred to by a common name. * This name represents the class or type of the objects. Ingredients * Atemplate or class specifies the ingredients or components that objects are made of. * These ingredients define the properties or attributes of the objects. Methods * A template or class also lists the methods or functions that objects can perform. * These methods define the behavior or actions that objects can take. Number of Classes * The number of classes is usually less than the number of objects. * Multiple objects can be created from a single class. Class vs. Objects * Aclass is like a blueprint that the program uses to create objects. * An object is an instance of a class, representing a specific entity or item. Finding Classes “To find classes, we can follow these steps: Check if there is already a class with the same properties and functionality as the object “If yes, use this class. “If no, proceed to the next step. Look for existing classes or modules in the Python Standard Library that have similar properties and functionality, "If yes, use one of these classes. “If no, proceed to the next step. If none of the previous steps apply, create a new class to represent the object.

You might also like