5.9 this Keyword
this keyword
a keyword that essentially refers to the object that is calling the method or the object that the constructor is trying to make</detail>
### Can be used 3 Ways:
1. **refer to instance variable** > This will solve the problem of having duplicate variable names. To distinguish the instance and local variables, we use this.variableName for the instance variable and simply variableName for the local variable.
2. **parameter** > Sometimes, we can also use the object as a parameter in its own method call to use itself in the method by using objectName.methodName(this).
3. **constructor or method call** > Sometimes, we can also use the object as a parameter in its own method call to use itself in the method by using objectName.methodName(this).
```python
public class Dog {
private String breed;
public String getBreed(){
return breed;
}
public boolean isSameBreed(Dog otherDog){
return
// breed.equals(otherDog.breed);
// this.breed.equals(otherDog.breed);
// **this** makes the code more readable/clear but is not required
}
}
```
```python
public class DogCompetition {
public boolean doBreedMatch (Dog dog1, Dog dog2){
return this.getBreed().equals(dog2.getBreed());
// **this** refers to object which was used to call doBreedsMatch and is a DogCompetition object, not dog object (CANNOT CALL getBreed())
// this.dog1
// dog1 is not data member (parameter) so incorrect
// doBreedMatch doesn't use any data from DogCompetition class no way to use this
}
}
```
What method should DoBreedsMatch should have been ? >> Static not instance (no instance data)
### Local vs Instance
Make the code a little clearer by using the **this** keyword
b,a,w,and s aren't meaningful parameters change them into breed, age, weight, and score
distinguish the local and instance variables using the **this** keyword
```python
public class Dog {
private String breed;
private int age;
private double weight;
private double score;
public Dog(sting b, int a, double w, double s){
// 1. make this code a little clearer by using the **this** keyword
// 2. change the parameters into something more meaningful
// 3. distinguish local vs instance variables using **this** keyword
breed = b;
age = a;
weight = w;
score - s;
}
}
```
set this as breed to b instead of breed = b set the object whose being contructed data meber to b
b a w and s arent meaningful parameter
differenciate vs local and instance valiable this.breed = instance vs breed = parameter
# 5.10 Ethical and Social Implications of Computing Systems
### Impacts
Programming affects the world in many ways, such as socially, economically, and culturally. For instance, not everyone has the same access to technology and computer programs, which creates social inequalities. Some people can use technology, while others can't. **Digital Divide**
The global economy relies heavily on technology and computer programs, especially in areas like stock trading and economic predictions. Programming and technology have also made the world more connected, allowing different cultures to mix and making it easier for people to communicate globally. However, this has also created a gap between generations, with younger people having more exposure to digital technology than older generations.
**These impacts on society, the economy, and culture can be both good and bad.**
### System Reliability
When programmers create software, they need to consider how reliable the system is. Different devices can perform the same task at varying speeds and in different ways. Each system may have security issues that hackers can exploit.
To make systems more reliable, programmers need to fix any bugs as soon as they find them. These fixes are then released to users as updates or patches to ensure that computers can be used safely and correctly.
### Intellectual Property
Usually, when people create programs on the internet, they own them. However, open source programs blur this line. In open source programs, anyone can make improvements to the code if the program owner allows it.
Licensing and access also play a role in letting others adapt and build on existing code to create their own programs. There are different types of licenses, like Creative Commons and MIT License, each serving different purposes.
Here is an [article](https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-license-to-a-repository) on how to add a license on your Repository