Skip to content

Commit

Permalink
remove inheritance stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
CassandraGoose committed Jun 9, 2023
1 parent ee42e00 commit e8cf563
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
78 changes: 0 additions & 78 deletions lessons/module-3/react-class-components-prework.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ By the end of this lesson, you will be able to:
- `this` - a keyword with a value that changes depending on the context in which it's used
- `class` - a special function which functionas as a template for creating objects
- `object instance` - objects that were created from a class and contain the data and functionality defined in that class
- `inheritance` - a mechanism which derives a class from another class; one class can inherit properties and functionality from a parent class

## Warm Up

Expand Down Expand Up @@ -191,83 +190,6 @@ Define a class of your own choice. Make sure it has some properties and at least
To test it out, instantiate the class (make an object instance).
## Inheritance
Sometimes, you'll have several classes that are very similar. They may have the same properties or the same functionality. We should work to DRY up our classes, just like we do with any other code. Consider the following class definitions:
```js
class Animal {
constructor(type, species, weight) {
type = type,
species = species,
weight = weight,
}

makeSound(sound) {
console.log(sound);
}
}
```
```js
class Dog {
constructor(weight, breed) {
type = 'Mammal',
species = 'Canine',
weight = weight,
breed = breed,
}

bark() {
console.log('woof!');
}
}
```
- What are all the similarities you see between these two classes?
- How does a 'dog' relate to the category of 'animal' in real life?
<section class="answer">
### Possible answers to the above questions:
Some similarities between the two classes are:
- similar properties: type, species, weight
- similar method: both the method makeSound and bark are doing the same thing.
A dog is a type of animal in real life. A dog could be considered a subcategory of the animal category.
</section>
This is a perfect time to implement inheritance. Instead of repeating ourselves so much, we can make the Dog class _inherit_ the properties it needs from the Animal class. Then, we could even make more classes that inherit from Animal, such as Cat or Llama.
We can make a class inherit from a parent class by using the `extends` keyword. We can then call the constructor of the parent class, which will give the Dog class access to the Animal's properties and methods by calling the `super` function.
```js
class Animal {
constructor(type, species, weight) {
this.type = type;
this.species = species;
this.weight = weight;
}

makeSound(sound) {
console.log(sound);
}
}

class Dog extends Animal {
constructor(type, species, weight, breed) {
super(type, species, weight);
this.breed = breed;
}
}

const fido = new Dog('Mammal', 'Canine', 10, 'Yorkshire Terrier');
fido.makeSound('Woof!');

```
<section class="note">
### Fun Fact
Expand Down
2 changes: 0 additions & 2 deletions lessons/module-3/react-class-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ By the end of this lesson, you will be able to:
## Vocabulary
- `this` - a keyword with a value that changes depending on the context in which it's used
- `class` - a special function which acts as as a template for creating objects
- `inheritance` - a mechanism which derives a class from another class; one class can inherit properties and functionality from a parent class
- `class component` - a React component that inherits properties and methods from a `Component` class.

<section class="call-to-action">
Expand All @@ -35,7 +34,6 @@ By the end of this lesson, you will be able to:

In small groups, answer the following questions. Make sure everyone has an oportunity to share and feel free to share screens.
- What do you know about JS classes?
- In your own words, desribe what inheritance is.
- How do you create a class in JS?
- How do you create an object instance using a class?

Expand Down

0 comments on commit e8cf563

Please sign in to comment.