CAB201 Programming Principles Lecture Notes PDF
Document Details
Uploaded by Deleted User
Queensland University of Technology
Tags
Summary
These notes cover Week 13 of the CAB201 Programming Principles course at the Queensland University of Technology (QUT). The notes detail the agenda for the week, including topics such as writing C# code, object-oriented design, and the final exam. Topics discussed include data types(text, numeric, boolean, enums), selection and comparison (if/else/else if, switch statements, user stories, and object-oriented design using class diagrams and UML diagrams).
Full Transcript
CAB 201 – Week 13 CAB201 – Programming Principles School of Computer Science, Faculty of Science TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science ...
CAB 201 – Week 13 CAB201 – Programming Principles School of Computer Science, Faculty of Science TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science ACKNOWLEDGEMENT OF TRADITIONAL OWNERS QUT acknowledges the Turrbal and Yugara, as the First Nations owners of the lands where QUT now stands. We pay respect to their Elders, lores, customs and creation spirits. We recognise that these lands have always been places of teaching, research and learning. QUT acknowledges the important role Aboriginal and Torres Strait Islander people play within the QUT community. TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Agenda Writing C# Code Weeks 1- 4 Object Oriented Design and Implementation Weeks 5 - 10 Final Exam Describe Practice Test TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Writing C# Code TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 1 – Data and Types Text based Strings e.g. "This is great" Characters e.g. 'a' Numeric Integral 1, 10, 50000, 1000000 (default int) Floating point numbers 3.14, 70.88, 14200.456 (default double) Booleans true, false Enums public enum Seasons { Spring, Summer, Autumn, Winter } TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 2 – Selection Comparison if/else/else if switch Comparison values Boolean, numbers, characters, Boolean strings Range Full Boolean range (==, !=, >, =, Netflix, Napster->Spotify Express user needs in user stories Then paired with Class Diagrams TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 6 – User Stories As a [type of user], I want [an action], so that [a benefit/a value] As a unit coordinator, I want to create a unit with a code, name and number of students, so I can teach it. As a unit coordinator, I want to set the first and last lecture times and dates, so that everyone turns up. As a unit coordinator, I want to change the number of students, as they enrol or leave the unit. As a unit coordinator, I wane use a command line menu interface, because they are easy to use. TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 6 – Object-Oriented Design 1. Start by identifying candidate classes in the application domain Look for nouns (tangible entities and more abstract concepts) Not all candidates will ultimately become classes. 2. What operations or methods might it have? Here we are looking for verbs What would each class be responsible for? 3. What fields/data might be associated with it. Look at nouns Looking at which classes own the field/data TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 6 – UML Diagram Class Diagram – Provides a high- level view of system showing classes, their attributes, methods, and relationships Use Case Diagrams – Interactions between users the system (functional) Sequence Diagrams – Sequence of interactions between objects Collaboration Diagrams – Emphasizes the relationships and communication between objects TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 6 – Modular Decomposition A Modular decomposition partitions a program’s code into a collection of modules (classes) The quality of a modular decomposition is assessed based on its coupling and cohesion – Cohesion – If the code within that class is closely related – Coupling – Low if the interaction between code from different class is minimal. – Coupling and Cohesion are both relative terms TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 7 – Inheritance When designing a system there will often be many similar classes Inheritance allows one class (child) to assume the features of another class (parent). And another class to inherit that child class (makes a tree) Child classes can be used in the same way as their parent Advantages Cuts down code/mistakes and increases polymorphism Allows child classes to extend the capacities of parent classes But allows child classes to be treated like parent classes Use :base keyword in constructor TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 7 – Protected Visibility Inheritance introduces the protected visibility Allows access to class and subclasses Same class Subclasses Other classes private Accessible Inaccessible Inaccessible protected Accessible Accessible Inaccessible public Accessible Accessible Accessible Access modifiers not shown here include: internal – can access from any code within the same assembly protected internal – can access from any derived class within the same assembly TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 - Polymorphism poly- From Ancient Greek πολύς (polús, “many, much”) -morph From Ancient Greek μορφή (morphḗ, “form, shape”) Same syntax can be used with different operands to achieve different outcomes depending on the context Polymorphism allows clean, reusable, extensible and easily understood solutions to be created Allows an object to interact with another object’s abstraction TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 - Polymorphism TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 – Operator Overloading Operators in C# behave differently to their operands int i = 1 + 2; // 3 string s = "Hello " + "World"; // Hello World You can also overload operations for your own classes Operators are overloaded using the operator keyword followed by the operator being overloaded The syntax is otherwise identical to declaring public static methods public static Ladder operator +(Ladder l1, Ladder l2) { return new Ladder(l1.Height + l2.Height); } TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 – Overriding Class A child’s method can override a parent’s method Child method will be used instead of a parent’s method The child’s method can be different/more specific Another example of extension The child’s method needs to have the same signature name, return type, parameters and visibility The parent’s method need to be declared abstract, virtual, override (already overridden its own parent) To hide the parent’s method the child method should be declared new TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 – Dynamic Dispatch If an object is declared and initialised as a child class child’s class method will be called Child var = new Child(); var.method() But you can declare an object as a parent class but initialise it as a child class Static type Runtime type Parent var = new Child(); var.method(); Which method is run? Only known at run time Override method - call child’s class method (good for collections) Hidden (new) methods - call parent’s class method TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 – Abstract Classes Abstract classes also allow polymorphism Abstract classes contain abstract methods and properties as well as non- abstract methods, properties and fields An abstract method does not contain a body Abstract classes cannot be instantiated but can be declared You don’t create a new class But it can be assigned to a decedent class In OOP design abstract class are used as a base categories of things that do not exist but a decedent can exist E.g. Pet is the base class, Cat and Dog are child classes TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 8 – Interfaces Interfaces are like abstract classes, but only contain abstract methods and static fields Classes can only inherent from one parent class, but can implement multiple interfaces Allows for polymorphism in the large (too complex than only using inheritance) Same base class but different behaviours e.g. animals some run, swim or fly Different base classes e.g. bird, plane, spaceship but all can fly Many interfaces have a small number of methods allowing custom utility code e.g. IComparable providess a CompareTo method for custom sorting TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 9 - Testing Valid Tests Invalid/Degenerate Tests Boundary Tests Over and under Equals Test Absence Tests TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 9 – System Testing Input Execute Output ================================= Welcome to Gardens Point Hospital 2 ================================= Please choose from the menu below: 1 1. Login as a registered user Bobby Smith Entered 2. Register as a new user 3. Exit Please enter a choice between 1 and 3. 28 Compare Register as which type of user: 0123456789 4. Patient 5. Staff [email protected] 6. Return to the first menu Please enter a choice between 1 and 3. HelloWorld123 Registering as a patient. Please enter in your name: Please enter in your age: Please enter in your mobile number: Please enter in your email: Please enter in your password: Bobby Smith is registered as a patient. Please choose from the menu below: 7. Login as a registered user 8. Register as a new user 9. Exit Please enter a choice between 1 and 3. TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J Goodbye. Please stay safe. CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 9 – Unit Testing Testing part of the system - Usually 1/a set of method/s [TestMethod] public void Test04_AddOneItem() { // Arrange int cap = 10; CollectionExample collection = new CollectionExample(cap); // Act int expected = 1122113; collection.Add(expected); // Assert Assert.AreEqual(cap, collection.Capacity); Assert.AreEqual(1, collection.Size); Assert.AreEqual(expected, collection); } TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Week 10 - SOLID Principles Single responsibility principle Open closed principle Liskov substitution principle Interface segregation principle Dependency inversion principle TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science QUT & Jacarandas = Exams TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Final Exam TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Final Exam 40 Multiple Choice Questions in random order Each question is worth 1 point 40% of your final grades Cover weeks 1 – 10 Mostly weeks 5 – 10 Week 10 – refactoring and SOLID principles Invigilated and closed book Most students are scheduled to a shared time and date Please check yourselves TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Practice Test TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Some tips Get plenty of rest. This might sound trivial, but you'd be surprised at how much good rest does for your exam preparations. Take care of yourself. Eat and have water before/during the exam. Use your perusal time to identify which questions are the easiest. If you just focussed on the tough questions, you may miss easy marks. For MCQ eliminate obvious wrong answer(s). If you get anxious/stressed/overwhelmed breathe, breathe then breathe again (slowly). It's easier said than done but try to relax a bit. Spending some time to clear your mind and reframe your mindset goes a long way during a stressful situation, such as an exam. Have a look at Kirsty lecture (Week 12) to help. Don’t be afraid to close your eyes and have a mini-meditation session mid-exam. Then get back to it. TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Conclusion of CAB201 So long, farewell, auf wiedersehen, goodnight TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science What have you learnt Requirements Analysis Design Implementation Programming Coding Testing Deployment Maintenance TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science What have you learnt Developed Introduced Data Classes Types Objects Methods Abstraction Collections Encapsulation Files, Directories Inheritance File I/O Polymorphism System Tests System Design Refactoring Objected-Oriented Design User Stores Unit Testing SOLID TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science What's Next? In object-oriented CAB302 – Software Development CAB301 – Algorithms and Complexity CAB402 – Programming Paradigms Skills Blockchain Technology, Machine Learning, High Performance and Parraell Computation, Artificial Intelligence TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Student Voice Survey Things we want to hear about… Gradescope What do you like/dislike about it Live Lecture & Hybrid/Online Recorded Content How can it be improved Discord/Peer Feedback If you have used Simulate Have you joined student groups And everything thing else TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science 2024 Student Elections Number of students who voted = 6731 Number of QUT Students = ~50,000 Percentage of students who voted = 1.35% https://qutguild.com/elections/ https://www.qutglass.com/guild-election-results-2023/ TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science CAB201 Congratulations on getting this far CAB201 is tough unit Especially for those will less programming experience High-level conceptions have been introduced Fill out the voice survey and vote in student council elections Goodbye and best of luck with your exams TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science Thank You TEQSA Provider ID PRV12079 Australian University | CRICOS No.00213J CAB201 – Programming Principles School of Computer Science, Faculty of Science