Angela Yu Course part 8 (up to lesson 94)
Continuing! Last time, classes were introduced. These seem to be - generally speaking - the way to go in all coding that involves objects. So the first part is going to be about object-oriented programming, something Pasan taught via the 'tower' game. That was a bit confusing to be honest, so hopefully this will clarify things! As before, I only have around half an hour - one our max, so here goes!
Object Oriented Programming
Machine Code - made up of 0 or 1.
Technically, you could run with MC and do billions of lines of this but it would take forever!
1970s - C programming language. This is where all the other languages came from.
Procedural Programming Language - Do this, then this, then this....repeated!
Restaurant analogy - ONE person doing a long list of things including waiting on the tables, taking the orders...etc etc. Instead, you could have one person for the waiting, one for cooking. Good analogy! So in the restaurant analogy, messages can be passed around between the 'objects'.
Modularising - splitting up the tasks and roles into separate objects!

A class is a BLUEPRINT. Contains the instructions for how to create the objects.
E.g. a class for a car is not an actual car! It contains the instructions, diagrams, information for how the car would be built and run.
That's made it clearer!
Properties - features/characteristics. Defined by let and var. When associated with an object they are called properties.
Actions - these are functions created within the class - for doing specific things. *Called methods within the function. When declared outside of the class - a function.
Events - how the objects respond to certain things happening.


These all make it conceptually clearer!

Question Bank Class
OK, so restaurant analogy again!
Data - the food - the raw ingredients
Model - the chef in the kitchen who cooks and prepares the ingredients
Controller - the waiter who goes between the kitchen and the tables
View - the table where the people are eating
I REALLY like this. I also love having M/V/C folders on the Xcode project. I will do this from now on EVERY SINGLE TIME!!!
That's it for now! Lots of useful takeaways again:
Using the MCV folders in the Xcode project
Using a dict question/answer within a class
Analogies to understand classes and MVC better
What design patterns are
So tomorrow I'll crack on with this and try to complete the Quizzler app.
Object Oriented Programming
Machine Code - made up of 0 or 1.
Technically, you could run with MC and do billions of lines of this but it would take forever!
1970s - C programming language. This is where all the other languages came from.
Procedural Programming Language - Do this, then this, then this....repeated!
Restaurant analogy - ONE person doing a long list of things including waiting on the tables, taking the orders...etc etc. Instead, you could have one person for the waiting, one for cooking. Good analogy! So in the restaurant analogy, messages can be passed around between the 'objects'.
Modularising - splitting up the tasks and roles into separate objects!
A class is a BLUEPRINT. Contains the instructions for how to create the objects.
E.g. a class for a car is not an actual car! It contains the instructions, diagrams, information for how the car would be built and run.
That's made it clearer!
Properties - features/characteristics. Defined by let and var. When associated with an object they are called properties.
Actions - these are functions created within the class - for doing specific things. *Called methods within the function. When declared outside of the class - a function.
Events - how the objects respond to certain things happening.
These all make it conceptually clearer!
Question Bank Class
class QuestionBank {
var list = [Question]()
init() {
// Creating a quiz item and appending it to the list
let item = Question(text: "Valentine\'s day is banned in Saudi Arabia.", correctAnswer: true)
// Add the Question to the list of questions
list.append(item)
// skipping one step and just creating the quiz item inside the append function
list.append(Question(text: "A slug\'s blood is green.", correctAnswer: true))
list.append(Question(text: "Approximately one quarter of human bones are in the feet.", correctAnswer: true))
list.append(Question(text: "The total surface area of two human lungs is approximately 70 square metres.", correctAnswer: true))
list.append(Question(text: "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.", correctAnswer: true))
list.append(Question(text: "In London, UK, if you happen to die in the House of Parliament, you are technically entitled to a state funeral, because the building is considered too sacred a place.", correctAnswer: false))
list.append(Question(text: "It is illegal to pee in the Ocean in Portugal.", correctAnswer: true))
list.append(Question(text: "You can lead a cow down stairs but not up stairs.", correctAnswer: false))
list.append(Question(text: "Google was originally called \"Backrub\".", correctAnswer: true))
list.append(Question(text: "Buzz Aldrin\'s mother\'s maiden name was \"Moon\".", correctAnswer: true))
list.append(Question(text: "The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.", correctAnswer: false))
list.append(Question(text: "No piece of square dry paper can be folded in half more than 7 times.", correctAnswer: false))
list.append(Question(text: "Chocolate affects a dog\'s heart and nervous system; a few ounces are enough to kill a small dog.", correctAnswer: true))
}
}
So all of this was created by Angela - obviously! What a great way of formatting all of the questions with the true/false answer to match!
Design Pattern
Best practice approach/proven solution to a common problem.
E.g. staying warm when it's cold!
Solution - animal hide...this would have all sorts of problem!
Solution - mud hut...still problems!
Modern house - the best solution! Well, good enough at least!
This is also a BLUE PRINT - best practice for creating something!
MVC ....
So the model MANAGES the data... It is responsible for creating new entries/editing/adding to the database.
View - what you see on screen
Controller - handles communication between the model and the view
OK, so restaurant analogy again!
Data - the food - the raw ingredients
Model - the chef in the kitchen who cooks and prepares the ingredients
Controller - the waiter who goes between the kitchen and the tables
View - the table where the people are eating
I REALLY like this. I also love having M/V/C folders on the Xcode project. I will do this from now on EVERY SINGLE TIME!!!
That's it for now! Lots of useful takeaways again:
Using the MCV folders in the Xcode project
Using a dict question/answer within a class
Analogies to understand classes and MVC better
What design patterns are
So tomorrow I'll crack on with this and try to complete the Quizzler app.
Comments
Post a Comment