Luyện nói tiếng Anh bằng Shadowing qua video: Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3)

Chọn chế độ luyện tập

Mỗi chế độ mở một phòng luyện tập toàn màn hình.

235 câu
Nếu các câu quá ngắn hoặc quá dài, hãy bấm Edit để chỉnh sửa.
1
Hey guys, this is part one of my introduction to classes
2
and objects and in this video I'm gonna talk about what are classes
3
and objects and then what are attributes methods and constructors
4
and at the end of this video I'm gonna give you some code samples in Java, but this video is gonna be mostly language independent
5
So you'll be able to use what you learn in this video in whatever language you're using
6
Classes and objects are actually one of the most fundamental topics when it comes to data structures and algorithms
7
So let's get started.
8
So what are classes and objects?
9
I think the best way to explain what they are would be to give you a really concrete example
10
So let's say as an example
11
You're thinking about making a website where people can you know visit and talk to a bunch of robots
12
So what you have in mind is you know when people feel lonely or something
13
They can come visit your website and say hi to one of the robots there
14
So when a user comes to your website, they might see a list of robots like this and here
15
You see two of those robots and they're called Tom and Jerry Aside from their names.
16
They have some obvious differences.
17
First of all
18
Tom's color is red while Jerry's color is blue as you can see
19
and and Tom is slightly lighter in weight than Jerry, with 30 pounds of weight, while Jerry is 40 pounds.
20
And they both have the same functionality.
21
You know, when you click this button, introduce, Tom will say, my name is Tom, and Jerry will say, my name is Jerry.
22
And that's all you have for now, and it's pretty basic, but that's all you want at the beginning when you create this website.
23
Now to create a system like this, you basically need a way to represent these different entities
24
Or these different robots in whatever programming language you're using
25
Whether it's Python, Java, or JavaScript And that's where classes and objects come in Now to represent each of these robots,
26
Tom and Jerry that we saw earlier
27
In whatever programming language you're using, you need to store two sets of information
28
The first set of information that you need to store is the properties that each robot has
29
So for example, the first robot we saw had these properties
30
Its name was Tom, the color was red, and the weight was 30 pounds
31
And the second set of information you need to store for each of these robots
32
Is the set of functionalities it has
33
As we saw earlier, it had only a single functionality in this particular case
34
And that was to introduce itself and that might be represented as a function in whatever programming language you're using
35
And let's just call it introduce self here for now
36
At this point you might say is there any convenient way to organize these properties and functions together
37
There is and that's called an object
38
An object is basically a collection of properties which can be expressed as variables and some functions
39
And with that collection of information, an object can represent something, whatever that thing is So in this particular case,
40
this particular object is representing this particular robot, Tom But you can make an object so that it represents a particular person,
41
or a particular dog, or anything else for that matter
42
If you decide to represent a particular person with an object,
43
let's say Lady Gaga, just as an example you might have a different set of variables
44
and a different set of functions to represent that person.
45
So for example, you might still have name, but you might also have height and weight, eye color, and ethnicity, and so on.
46
And your object will probably have a different set of functions too, to show what kind of actions that person can take.
47
It could be for example, things like walk, sleep, talk, or anything a person might do.
48
Okay, let's backtrack here a little bit.
49
Once you create an object to express this particular robot, Tom, you'll be able to put this object in a variable just like that.
50
Let's say r1 just as an example, and you'll be able to use this variable that contains this whole set of information,
51
you know, the properties or the variables and the functions, just like any other variables.
52
For example, to pass it into a function as one of the arguments.
53
Okay, let's now take a look at how the second robot we saw, Jerry, can be represented with an object.
54
It's going to look pretty similar to the first one.
55
It's going to have the same set of properties, but different values, this time
56
Jerry, Blue, and 40, and the same function as well, introduce self.
57
And of course, once you create this object, you'll be able to put it in a variable as well.
58
Let's call that one R2.
59
And because you have two distinct variables containing two different objects, you'll be able to distinguish them very easily in your code.
60
And just quickly about terminology, these variables within an object are called either instance variables or attributes,
61
And these functions within an object are called methods
62
Okay, so when you see these two objects, you might say, well, they're pretty similar
63
They have the exact same set of variables or attributes and they have the exact same set of functions
64
Only one function in this case
65
So you might say is there any convenient way to organize that somehow?
66
There is and that's what a class is essentially
67
Now what's a class?
68
A class is basically like a blueprint from which you can make objects
69
So just imagine for a second someone telling you, please make a robot
70
If someone tells you something like that, you'll say, you know, what kind of robot do you want?
71
What should it look like?
72
And what kind of properties should it have?
73
And what kind of functionalities should it have?
74
So basically, if you want to make a robot in sort of the real world
75
You'd need a blueprint to make the from to know what the robot should look like
76
And that's sort of how it works with programming with objects and classes too
77
So when you make an object, you'll want to know what kind of properties
78
What kind of attributes it'll have and what kind of functions it'll have
79
And you can use a class to specify exactly that
80
Okay, let's now see what this particular class might look like
81
For these two objects, these two robots it'll probably look like this as you can
82
see it has the same set of properties as the objects themselves name color
83
and weight but the values for these three properties are not defined yet
84
and that's because a class doesn't refer to any particular object it doesn't refer to this robot
85
or this robot in particular it just refers to this category of robots or this type of robot in general
86
And then when you create a specific object using this class
87
Then you can specify what the name should be what the color should be and what the weights should be and
88
Also notice here that we already have the introduce self function in this class
89
You can actually implement it already when you define this class by writing something like this
90
So this is just an example from Java in Java for printing something on your computer we have system .out .println.
91
It's similar to the print function or the printf function in other languages, and then inside the input of this function,
92
we have my name is as a string plus name,
93
and this name will refer to whatever the value of the name is for that particular object.
94
So for example, if you run this function in In this object, it's going to print out,
95
my name is Tom, because that's the name of this particular object.
96
And then if you run this function here in this object instead, it's going to print out, my name is Jerry instead.
97
And one more thing to note here is that when you define a class like this one, you need to give it a name.
98
It could be anything, but let's call it robot here.
99
And as you can see the first letter R is capitalized and that's a pretty common convention when you name a class
100
Okay, let's now take a look at how this whole thing might look like in code
101
We're gonna take a look at some code in Java here, but other languages are typically pretty similar
102
And let's first assume that we already have our class defined
103
Like we said it's gonna be called robot, but we're gonna take a look at what's gonna go inside later and
104
And once you define this class robot you'll be able to use
105
this class of course to create an object out of it
106
And you can do that like this we have robot r1 equals new robot
107
and this new robot Parentheses says create a new object with this class robot and then we're
108
Assigning that object to r1 and then we have the word robot here again
109
because a class is used not just to create an object but also as a type too.
110
You know, just like we say string r1,
111
if we want to create a string we can say robot r1 to create a reference to a robot object.
112
Okay, let's move on.
113
When you create a new object this way, this new object doesn't have the properties, doesn't have its instance variables set yet.
114
So you need to set them after that, just like that.
115
Here we have r1 .name equals
116
Tom, and that sets the name attribute of this object, or the name instance variable of this object, to Tom.
117
And then you need to do the same thing for the
118
other two instance variables by saying r1 .color equals red and r1 .weight equals 30
119
So that's the first object r1
120
Let's see how we can create a second object here
121
As you can see the second block of code here is pretty similar to the first block
122
We have robot r2 equals new robot to create a new object
123
And then we have r2 .name equals
124
Jerry and so on to set the instance variables of that object
125
So that's how you can create two objects of the robot class here
126
But what about the functionality we saw earlier, introduceSelf To run the function for each of these objects, the syntax for that is actually pretty simple
127
It's going to look like this
128
We have r1 .introduceSelf This just says run this function introduceSelf on this object r1
129
So when you run this line, it's gonna print out my name is Tom
130
because this robot's name is Tom
131
And then you can do the same thing for r2 by writing r2 .introduceSelf
132
And that's gonna run this function introduceSelf for r2
133
And then it's gonna print out my name is Jerry Okay, let's now see how you can actually define this class
134
First of all, to define what instance variables this class will have
135
You can just write these
136
This of course says the instance variables that this class will have are Name, which is going to be a string color,
137
which is a string as well and weight
138
Which is an integer and when you see other sample code in Java, you might see words like public
139
Private or something else before each of these attributes
140
But just to keep this simple I'm not going to talk about what they are in this particular tutorial
141
and when you run this code
142
It will just work just fine without adding these words, too Okay, the next thing you need to define
143
and implement is this function introduce self and for that you can write this
144
Here we are defining a function called introduce self
145
and we have the void Prefix here to show
146
that this function is not going to return anything and notice that this function
147
Definition is still inside this class and then the implementation is as we saw earlier system .out .println, my name is this .name.
148
Actually, we could just have name here, but I wrote this .name instead, just for emphasis.
149
So what's this here?
150
This refers to whatever object, whatever particular object that you're running this function on.
151
So if you write r1 .introduce self, you're running this function on r1, so this will be equivalent to r1.
152
So it's going to be sort of like saying system .out .println, my name is r1 .name, which is going to be Tom, of course.
153
And then when you run r2 .introduceSelf, this will refer to this keyword, will refer to r2 instead.
154
So when you run r2 .introduceSelf, it's gonna print out my name is r2 .name, which is Jerry.
155
Okay, so that's the basics of classes and objects in Java.
156
But when you look at these two blocks of code, you might say, well, they're pretty repetitive
157
You know, you need to repeat the same things over and over again
158
And then it's pretty cumbersome to remember to set these attributes every time too
159
Every time you create an object
160
So you might say, is there any way to simplify that?
161
There is, and it's called a constructor A constructor is basically a function
162
that allows you to create an object from a class
163
And then you'll be able to use the constructor to, you know, do things like set the attributes for yourself
164
And actually you already used a constructor, you know, this line right here new robot
165
That's a constructor, but that's a default constructor that java defines for you
166
And this constructor doesn't set any of the attributes
167
So let's see how we can create our own constructor that does set the attributes for you
168
So that constructor might look like this
169
So if you see this function, you'll notice that, you know, it looks like a regular function
170
Except for that we don't have any prefix here, like void or string for the return value
171
Instead, this function, this constructor is just called robot
172
Notice that that name is exactly the same as the class name
173
And then it has three arguments
174
String n, string c, and int w
175
And then inside this function, we're setting this .name to n, this .color to c, this .weight to w.
176
As we saw earlier, this refers to the particular object that we are talking about here.
177
In this case, the particular object that has just been created.
178
And then we're saying that object's name should be n, which is the given argument.
179
And then that object's color should be c, which is the given argument, and so on.
180
And then here, the common practice here is to name these arguments exactly the same as these attributes, name, color, and weight.
181
And with that, this part is going to look like this .name equals name, this .color equals color, this .weight equals weight.
182
But with that naming, this function, this constructor, is doing exactly the same thing as this one.
183
So that's really just a style issue.
184
Okay, moving on, we're almost done here.
185
Let's see how we can actually use this constructor
186
And actually when you define your own constructor your own custom constructor the default constructor stops working
187
So these two blocks of code no longer works and then you can use this new constructor to create new objects
188
Just like this this one says
189
Robot r1 equals new robot
190
Tom red and 30
191
So these three arguments tom red and 30 will be passed on to this constructor
192
And then this block of code is going to be run
193
And so r1's name is going to the given n which is tom
194
And then the color will be red and then weight will be 30
195
So this piece of code will actually be equivalent to the whole block of code we had earlier right here
196
Basically create a new object and then set the attributes to the given arguments
197
And then we can do the same thing for r2 as well
198
By writing robot r2 equals new robot jerry blue and 40
199
This creates a new robot object with the name jerry color blue and weight 40
200
And after creating these two objects you'll be able to use r1 and r2
201
Just like before by writing r1 .introduce self and r2 .introduce self
202
Okay, again, this was just sample code in Java But it's pretty similar to other languages,
203
too And you'll be able to find links to sample code in both
204
Java and Python in the description below
205
Alright, if anything was unclear in this video, please let me know in a comment below
206
So maybe I can talk about it in the next video.
207
In the next video I'm also going to talk about how you know multiple classes
208
and objects can interact with each other and with that knowledge
209
You'll be able to finally start building some data structures like link lists I'm also planning to create a new
210
Python tutorial video on classes and objects.
211
So look out for that as well and Special thanks to brilliant .org for sponsoring this video
212
You know some of you may already be familiar with data structures and algorithms
213
And maybe you're watching my videos as sort of a refresher if that's the case
214
Brilliant .org might just be the right website for you to learn more advanced concepts in computer science
215
So personally I use this computer memory course to get a better understanding of how memory works in a computer
216
For example previously I didn't really know how structs in C are stored on memory I mean I had a vague idea,
217
but I didn't really know and I found this course was really helpful for understanding that
218
Personally, what I like about Brilliant is first of all the fact that they have really nice visuals like this one
219
You know much nicer than mine, I would say and they're helpful for understanding different concepts visually
220
And another thing I like is the fact that they sometimes combine multiple concepts in a single problem
221
What I mean by that is for example for this particular problem
222
You need to understand different things like binary expressions
223
and how structs in C are stored on a computer
224
and how short and car and different types of data are stored on memory too.
225
And in my experience in general I have found
226
that you know solving problems is a really good way to review different concepts at the same time
227
and also learn new concepts.
228
And Brilliant .org definitely does a good job of coming up with good problems to solve.
229
And they even have pretty advanced courses like this artificial neural
230
networks course on top of their standard computer science fundamentals and algorithms courses.
231
You can just go to brilliant .org slash csdojo to start checking out these courses yourself
232
and you can get a 20 % off their annual subscription through that link as well.
233
Alright, as always, I'm YK from csdojo and you know I'm working really hard here to make csdojo better
234
and better so that hopefully eventually it's gonna be in a class of its own.
235
Alright, I will see you in the next video.

Tải Ứng Dụng

Mọi thứ bạn cần để nói trôi chảy

Chấm điểm AIChấm từng câu nói
Luyện IPAThành thạo mọi âm
Từ vựngMở rộng vốn từ
Game Từ vựngHọc qua chơi

Cùng kênh

FOR YOU

Video gợi ý

Từ vựng và ghi chú luyện nói cho bài học này

Bài luyện nói này dựa trên video “Introduction to Classes and Objects - Part 1”. Những từ được nhắc lại nhiều nhất trong bài: object, robot, function, create, constructor. Video này có 235 câu và 3271 từ để luyện shadowing. Phần lời nói dài 19:50. Người nói nói với tốc độ tự nhiên, khoảng 165 từ mỗi phút, gần với hội thoại hằng ngày. 86% số từ nằm trong 3.000 từ tiếng Anh thông dụng nhất; phần còn lại nên xem trước khi luyện.

Từ vựng quan trọng trong video

15 từ đáng học trong video, kèm phiên âm và nghĩa:

TừPhiên âmNghĩa
robot danh từ/ˈɹoʊ.bɑt/người máy, rô-bốt
attribute danh từ/ˈæt.ɹɪˌbjut/định ngữ
introduce động từ/ˌɪntɹəˈdus/giới thiệu
string danh từ/stɹɪŋ/chuỗi
algorithm danh từ/ˈælɡəɹɪðm̩/thuật toán
helpful tính từ/ˈhɛlp.fl̩/hay giúp đỡ
solve động từ/sɒlv/giải quyết
default danh từ/dɪˈfɔlt/mặc định
implement động từ/ˈɪmpləmənt/thực hiện, chấp hành
convenient tính từ/kənˈviː.niənt/tiện lợi
organize động từ/ˈɔɹɡənaɪz/sắp xếp, tổ chức
topic danh từ/ˈtɑpɪk/chủ đề
custom danh từ/ˈkʌstəm/tập quán, phong tục
lonely tính từ/ˈloʊnli/cô đơn, lẻ loi
artificial tính từ/ˌɑː.tɪˈfɪʃ.əl/nhân tạo

Cụm động từ bạn sẽ nghe

TừNghĩa
check out động từtính tiền, trả phòng

Ngữ pháp trong video

Những cấu trúc người nói dùng nhiều nhất, kèm đúng cụm từ trong video:

Cấu trúcTrong video
Câu điều kiện if + mệnh đề, will/would + động từ — điều kiện và kết quảif you see this function, you'll notice
Câu bị động be + quá khứ phân từ — nhấn vào việc xảy ra, không phải người làmmight be represented · can be expressed · can be represented
Mệnh đề quan hệ who / which + mệnh đề — thêm thông tin về người hoặc vậtproperties which can · Name, which is
Thì hiện tại hoàn thành have/has + quá khứ phân từ — việc đã xảy ra nhưng còn liên quan đến hiện tạihas just been created · have found

Phát âm cần chú ý

Người nói dùng 62 dạng rút gọn, ví dụ you'll, gonna, you're. Hãy nói theo dạng ngắn đúng như bạn nghe.

  • Âm “th”: algorithm /ˈælɡəɹɪðm̩/, ethnicity /ɛθˈnɪsɪti/
  • Âm “sh” và “zh”: essentially /ɪˈsɛnʃəli/, implementation /ˌɪmplɪmənˈteɪʃən/, artificial /ˌɑː.tɪˈfɪʃ.əl/, subscription /səbˈskɹɪpʃən/, distinguish /dɪˈstɪŋ.ɡwɪʃ/
  • Từ dài — đặt trọng âm cho đúng: fundamental /ˌfʌn.dəˈmɛn.təl/, essentially /ɪˈsɛnʃəli/, implementation /ˌɪmplɪmənˈteɪʃən/, artificial /ˌɑː.tɪˈfɪʃ.əl/, entity /ˈɛn.tə.ti/ [-tʰi]

Những âm người Việt thường gặp khó:

  • Cụm phụ âm cuối — đọc đủ từng âm, đừng nuốt âm cuối: pound /ˈpaʊ̯nd/, solve /sɒlv/, default /dɪˈfɔlt/, implement /ˈɪmpləmənt/, convenient /kənˈviː.niənt/
  • Âm /tʃ/, /dʒ/ và /ʒ/ — tiếng Việt không có, đừng đọc thành “ch” hay “gi”: java /ˈd͡ʒɑː.və/, terminology /ˌtɝ.məˈnɑ.lə.d͡ʒi/, integer /ˈɪn.tɪ.d͡ʒə(ɹ)/
  • Âm /æ/ — mở miệng rộng hơn âm “e”: variable [ˈvæɹ.i.ə.bl̩], attribute /ˈæt.ɹɪˌbjut/, algorithm /ˈælɡəɹɪðm̩/, interact /ɪn.təˈɹækt/, syntax /ˈsɪn.tæks/

Cách luyện với video này

  1. Nghe hết video một lần, chưa cần nói, và ghi lại những từ bạn chưa biết.
  2. Bắt đầu ở tốc độ 0,75×, nói đuổi từng câu, rồi quay lại tốc độ bình thường khi đã quen.
  3. Ghi âm giọng mình rồi so với bản gốc, chú ý các từ như robot, attribute, introduce.

Phương Pháp Shadowing Là Gì?

Shadowing là kỹ thuật học ngôn ngữ có cơ sở khoa học, ban đầu được phát triển cho chương trình đào tạo phiên dịch viên chuyên nghiệp và được phổ biến rộng rãi bởi nhà đa ngôn ngữ học Dr. Alexander Arguelles. Nguyên lý cốt lõi đơn giản nhưng cực kỳ hiệu quả: bạn nghe tiếng Anh của người bản xứ và lặp lại to ngay lập tức — như một "cái bóng" (shadow) đuổi theo người nói với độ trễ chỉ 1–2 giây. Khác với luyện ngữ pháp hay học từ vựng bị động, Shadowing buộc não bộ và cơ miệng phải đồng thời xử lý và tái tạo ngôn ngữ thực tế. Các nghiên cứu khoa học xác nhận phương pháp này cải thiện đáng kể phát âm, ngữ điệu, nhịp điệu, nối âm, kỹ năng nghe và độ lưu loát khi nói — đặc biệt hiệu quả cho người luyện IELTS Speaking và muốn giao tiếp tiếng Anh tự nhiên như người bản ngữ.

Phương pháp shadowing: đọc hướng dẫn từng bước đầy đủ →