Prime Reacts: The Flaws of Inheritance - YouTube

Channel: unknown

[0]
all right are you ready for this let's
[2]
do this are you ready for the first one
[3]
then the flaws of inheritance by the way
[5]
so this is very this is let's say marker
[8]
let's see hold on ah the flaws of
[10]
inheritance
[12]
all right
[13]
so real talk I think that this person
[15]
right here code Aesthetics is like one
[17]
of the best coding YouTubers right now
[19]
he has five videos up in a hundred and
[22]
fifty thousand Subs like the guy I don't
[25]
know what he does it's just awesome and
[28]
I saw one of his videos and I loved it
[30]
so I wanted to watch another one I just
[33]
wanted to see what he made here and so
[35]
let's watch this you may have heard the
[37]
saying prefer okay let's turn that down
[40]
let's let's let's try that again let's
[42]
just try that immediately again but turn
[45]
it down because I think we all just got
[47]
done experiencing what some people refer
[49]
to as an eargasm but other people refer
[52]
to as dying from loud sounds all right
[54]
here we go you may have heard the saying
[56]
prefer a composition over inheritance
[59]
the advice is a little vague so I'm
[61]
gonna break it down what is composition
[63]
inheritance and why would you prefer one
[65]
over the other
[71]
both composition and inheritance are
[73]
trying to solve the same problem you
[75]
have a piece of code that you're trying
[76]
to reuse
[78]
inheritance is when you have a class
[80]
that contains functionality you want to
[82]
reuse so you create a subclass extending
[84]
its functionality
[86]
if you if this guy sucks actually what
[89]
was I saying here is amazing do you see
[90]
where his squirrely braces are okay do
[93]
you see
[94]
where his squirrely braces are what is
[96]
this C sharp what are we looking at
[98]
right now
[99]
ridiculous okay who puts next line
[102]
squirrely braces okay this is absurd can
[104]
we can we
[107]
everyone go go subscribe to him and then
[110]
tell him that his squirrely brace
[112]
placement is awful
[115]
yeah code Aesthetics my ass more like
[117]
Athletics you've basically created a
[120]
copy of the class with a new name
[122]
and then you can inject new methods to
[124]
extend or override parts
[126]
whoopsies oh my goodness
[128]
um sorry I don't know what just happened
[129]
there I got super excited apparently
[131]
then you can inject new methods to
[133]
extend or override Parts you know when
[135]
you're sold this in college or you're
[138]
shown this in college or you're shown it
[139]
for the first time it seems like this
[142]
makes perfect sense every single time I
[147]
feel like this makes perfect sense like
[149]
somehow
[151]
this is the way you should solve things
[153]
like like on paper this feels really
[157]
reasonable
[161]
we have a rudimentary image class here
[164]
it represents an RGB image and stores it
[167]
as a double array of pixels the image
[169]
class hides how the image is stored in
[171]
memory and provides a method for looking
[173]
up pixel values
[174]
we also have some stuff we can do to the
[176]
image
[177]
we have a resize what language is this
[180]
this is this is C sharp right am I am I
[183]
catching this correctly what I don't I
[185]
don't I don't understand this thing
[186]
right here
[190]
okay it is C Sharp I assume that's just
[193]
like doing okay I get it it's D sharp
[195]
hey type one in the chat if you love C
[197]
sharp come on let's see it let's go
[198]
let's go let's run it let's go make it
[202]
happen
[205]
there you go I love all the twos let's
[206]
go let's go look at all those two
[212]
knew it I knew none of you liked it I
[215]
knew none of you liked it you guys just
[217]
think you do hey but real talk I think
[219]
the guy's doing uh I think this person
[221]
here code code Aesthetics is is using
[224]
Vim to write C sharp okay hey that's
[227]
cool
[228]
method which resizes the image by scale
[230]
factor and we have methods to flip the
[232]
image horizontally or vertically
[236]
the library should support jpeg ping and
[238]
bitmap images
[240]
but we also want to reuse all of these
[242]
methods for the different types of
[243]
images
[245]
so to support loading and saving these
[247]
images we add two abstract methods save
[250]
and load
[252]
I feel like this is where everything's
[254]
going to fall apart
[256]
I can already feel like inside of my
[258]
heart
[260]
this feels so right this feels like
[262]
exactly how you would do it
[267]
and then all of a sudden
[269]
it's just like she goes so wrong you're
[272]
like oh crap
[274]
um well the flip it vertically in ping
[277]
you need to do you know it just it all
[279]
then you just it's just it's just the
[281]
worst
[283]
and then we create the subclass jpeg
[285]
image ping image and bitmap image
[289]
it's always the same crap it is always
[292]
the same crap look at this yeah this
[294]
looks beautiful this is this is great
[295]
honestly there's different versions of
[297]
load and Save
[298]
this is great
[301]
but also get all of the other methods
[303]
for free you don't like me calling it
[304]
ping
[306]
a PNG is called a ping
[309]
an sng is called a sing
[311]
what's wrong with you guys
[313]
and a gif is called a gif everybody
[316]
knows this
[330]
a webp no that's actually a webp
[333]
okay no one actually calls it webp they
[335]
all they call it w-e-b-p
[338]
ring
[340]
so when we load a JPEG image or a ping
[342]
image we can call resize on it and then
[345]
we save it the resize method is reused
[348]
for all of the image types
[350]
or save the overwritten version is
[352]
called instead
[354]
this works well but now we want to
[356]
create a version of an image that
[357]
doesn't come from a file at all but
[359]
instead has some methods that allow the
[361]
user to draw on the image
[363]
so we create a drawable image class and
[366]
inherit from our parent image class yeah
[368]
and this is where inheritance starts to
[371]
have issues
[372]
the downsides of inheritance is that
[374]
you've coupled yourself to the parent
[376]
class
[377]
the structure of the parent is thrust
[379]
upon the child
[381]
nothing like a good old-fashioned
[384]
for a thrusting forced to implement
[387]
these two load and save methods in order
[389]
to reuse our resize and flip code even
[392]
though they don't make sense for our
[393]
subclass
[395]
all we can do is have these two methods
[397]
throw an exception
[399]
to prevent this we need to remove this
[400]
method from our parent class and add a
[402]
new parent class in between called file
[404]
image that contained these two methods
[406]
my goodness this is like giving me
[407]
nightmares I can already feel one time I
[409]
made a game that was like a basic Galaga
[411]
Style game uh this was in C sharp a long
[414]
time ago with the XNA engine you may not
[416]
you probably most of you probably
[417]
weren't even alive when X9 came out and
[422]
oh my I at one point I think I had seven
[425]
layers of inheritance it is where I
[427]
realized I hate inheritance is is in the
[431]
XNA
[433]
welcome to Costco I love you thank you
[435]
vomitos oh my goodness vamanos just did
[437]
it he did the Subscribe then the follow
[440]
okay hey priorities
[442]
priorities of course what do you mean
[446]
you have a game object that has a a
[449]
position and an image associated with it
[452]
or you just have a position then you
[454]
have a drawable game object then you
[456]
have a movable game object that inherits
[459]
from drop because you know not all
[460]
things drawn actually move and then you
[463]
also may have an acceleration if you
[465]
wanted to add an acceleration so you
[466]
might have an acceleratable object I
[468]
don't know I don't know I was 19 years
[471]
old trying to figure out game
[473]
programming reading XNA books
[477]
from the internet
[479]
and guess what I ended up with seven
[481]
layers of inheritance okay I didn't know
[483]
what I was doing but I hated it I hated
[485]
it I hated it and I learned then and
[488]
there I hate inheritance but I didn't
[490]
know what to do better
[491]
but this also breaks anyone who
[493]
currently expects the image class to
[495]
contain those methods yeah when new
[497]
changes like this come we're forced to
[499]
edit all our classes a very expensive
[502]
refactor
[504]
this is the greatest downfall of
[506]
inheritance
[508]
I find it similar to how the ideal
[510]
cleanest database schema often causes
[512]
problems when you need to scale
[514]
we've moved to nosql databases with tons
[517]
of dirty duplication inheritance breaks
[520]
down
[521]
I don't I don't agree with that last
[523]
point
[526]
I feel like I I've been following this
[528]
guy like me and him tracking one-on-one
[531]
right there so good and then he just
[533]
throws out my squeal or no squeal just
[536]
like you can't be just tossing out no
[538]
squeal when we're talking about
[539]
inheritance like that okay that's just
[542]
when you need to change the code change
[544]
is the enemy a perfect design and you
[546]
often paint yourself into a corner early
[548]
on with your inheritance design dude
[551]
this is why capital D design like people
[553]
that go into a room and design a system
[555]
first fully on paper boxes and arrows
[558]
all this kind of I tell you what
[560]
this is exactly why it doesn't work this
[563]
is like it's this it's this right there
[566]
is that you go in you make all these
[568]
decisions and then guess what ends up
[570]
happening something because your
[571]
co-worker's like yeah I need all the
[574]
video frames as well and you're just
[575]
like
[580]
I just met with you yesterday what do
[583]
you mean you need the video frames uh
[586]
I forgot are you today I open it up and
[589]
now I just need I just need it I need it
[591]
today I didn't need it yesterday and
[593]
you're just like me I'm done I I
[595]
actually just I'm done I cannot build my
[597]
product I have to throw away my entire
[599]
design my capital D design
[602]
I I really I'm all about the the triple
[606]
method so if I'm making software to like
[608]
what I consider a Perfection level I
[610]
make it three times if I'm making it to
[611]
what I consider like production quality
[614]
I make it twice uh first time I just go
[617]
in there and I just like dicks out for
[619]
harambe and I just go I I mean I'm just
[622]
code right you're just in there
[624]
you're just making stuff you're yelling
[626]
dicks out for harambe and boom you come
[628]
out with like a one file 600 lines you
[631]
don't know what happened fever dreams
[632]
sweat coming out the crack like right
[634]
like it's just like something happened
[635]
from here to here and then you take a
[638]
step back you understand the problem and
[640]
that's when and how and where you fix it
[642]
you know what I mean digs Out Boys big
[644]
dick energy can I get some Dr Pepper you
[646]
know what I mean you know see what the
[648]
I have to deal with am I doing a
[650]
good as men gold AI
[652]
you see the kind of I have to deal
[653]
with I get these messages all the time
[655]
okay the big dick energy boys you know
[657]
uh the big dick Energy number one
[660]
himself out here just trying to drink a
[661]
little bit of Dr Pepper
[663]
but anyways
[665]
real talk like
[668]
this is really the only constant you
[671]
should expect in anything you build is
[673]
change and that's why you should try to
[675]
make as minimal amount of coupling as
[677]
possible
[679]
cat girls everybody knows cat girls big
[682]
boobs is way hotter
[684]
this is because inheritance naturally
[686]
asks you to bundle all common elements
[688]
into a parent class yes but the soonest
[690]
you find an exception to the commonality
[692]
it requires big angles can we just like
[694]
take a moment here again this guy just
[697]
incredible ability to talk about like to
[700]
to create an animation that's so
[703]
perfectly just displayed like all of our
[706]
thoughts together like look at that like
[707]
everybody totally understood like this
[710]
look how good that word naturally asks
[712]
you to bundle all common elements into a
[715]
parent class but the soonest you find an
[717]
exception to the commonality it requires
[719]
big changes
[720]
so
[722]
our alternative is to use composition
[724]
so what is composition
[727]
you've already been doing it
[729]
composition is the pattern you're doing
[731]
whenever you reuse code without
[733]
inheritance if we have two classes and
[736]
they want to reuse code they simply use
[738]
the code
[740]
let's change our image classes to be
[742]
composed instead
[744]
first we're going to remove our abstract
[746]
methods first off I'm actually really
[748]
excited about this I think this is
[749]
actually a pretty cool idea that's going
[751]
on right here
[752]
no one ever shows you like really
[754]
concrete ways to do things there's a lot
[756]
of
[757]
um
[758]
what's called uh
[760]
how how do you say this there's a lot of
[763]
uh whiteboard masturbation that goes on
[766]
and there's not usually a lot of
[767]
concrete stuff so I'm actually very
[768]
excited about this I think he's doing a
[769]
really good job right here and so
[772]
I really hope this this goes well
[776]
from image
[778]
that was David hassloff and thank you
[780]
very much I genuinely appreciate that 10
[783]
bangers doctorial
[787]
Syria I gave up the map I know it's a
[790]
different material I know Diablo 3 is
[791]
not spelled that way just let me just
[792]
let me have my moment okay just let me
[794]
have my moment
[797]
now this is no longer an abstract class
[799]
it's simply a class that represents an
[801]
image in memory
[804]
in our jpeg ping and bitmap classes
[807]
we no longer inherit image
[810]
but we'll keep our save and load methods
[812]
they'll just now be stand alone not
[814]
overriding anything
[816]
the methods were accessing a bunch of
[817]
stuff from the parent class so what do
[819]
we do about those well instead of
[822]
accessing them through this
[824]
will simply pass in the image in
[826]
question instead
[827]
it's
[829]
I'm liking that so far operations on top
[832]
of an image is really nice
[837]
this is really really nice like this is
[838]
this is kind of what you want to see
[840]
already I'm enjoying this a lot a lot
[842]
more right now I'm I'm really enjoying
[844]
this this is definitely no hand wavy
[845]
you're definitely right stegan
[848]
so now image represents an image and
[851]
these other classes cleanly represent a
[854]
specific file format
[856]
I can't look at that I'm going to vomit
[857]
oh gosh for whatever reason smooth
[860]
scrolling makes me want to vomit
[863]
now if our new drawing requirement comes
[865]
in we create an image draw class that
[867]
takes an image to draw to and the
[869]
methods do their thing we're no longer
[871]
bundled to the file related stuff
[874]
because we didn't force all the common
[876]
elements into a parent class we don't
[878]
need to alter any of the other classes
[880]
to add or image draw a class
[882]
now the user no longer chooses the one
[884]
class that suits their needs they also
[886]
combine classes together for their
[888]
particular use case so here we're
[890]
loading a JPEG image drawing to it and
[892]
then saving it
[894]
another app could do something different
[895]
like load a bitmap image flip it resize
[898]
it and then save it out as a ping
[902]
inheritance is interesting because it
[904]
actually combines two capabilities the
[906]
ability to reuse code but also the
[908]
ability to build an abstraction
[911]
creating abstractions allow a piece of
[913]
code to reuse another piece of code but
[916]
to also not know which piece of code
[917]
it's using you define a contract that
[920]
both sides of the abstraction agree to
[921]
this gives the code the rough shape of
[924]
the other code but it doesn't know
[925]
exactly what it is
[927]
inheritance does this by allowing a
[929]
consumer to think it's taking a class
[931]
but it's actually given a subclass
[933]
instead
[934]
then the code can operate like it always
[936]
does even if the system as a whole is
[938]
doing something very different if we go
[940]
back to when our image code using
[941]
inheritance our application used the
[944]
natural abstraction capability of
[945]
inheritance by storing references to the
[948]
parent class
[949]
when our app opens a file we just figure
[952]
out which subclass to create and then
[954]
store a reference to it through the
[955]
parent class
[957]
lesson polymorphism is great
[960]
interfacing is great
[971]
then when the user clicks the save
[972]
button our save clicked method will get
[975]
invoked and we'll just call the save
[977]
method and we're abstracted from whether
[979]
it's the jpeg ping or bitmap
[981]
but with composition you don't have
[983]
parent classes you're just using the
[985]
types you want
[987]
inheritance allows you to abstract
[988]
because the methods of the parent class
[990]
forms a contract a contract that says
[993]
that every child's class shall have at
[995]
least these methods
[996]
so for our new classes without
[998]
inheritance we still want to be able to
[1000]
call or save and load methods without
[1002]
caring about which class it is
[1005]
this is where interfaces come in instead
[1008]
of a full parent class with all its
[1010]
variables and methods an interface
[1011]
simply so I do think
[1014]
oh let me let me let me hear what he has
[1016]
to say describes the contract of what an
[1018]
object can do
[1020]
in this case we'll create an interface
[1022]
called image file which I do think that
[1024]
this is one of the big downfalls of
[1027]
typescript which is they allow for
[1030]
properties
[1032]
and methods in their interface I really
[1034]
love interfaces
[1036]
and
[1037]
interfaces
[1040]
allow you just to have like a shape of
[1042]
your data right a facade over what it
[1044]
actually is and it's just fantastic to
[1046]
have these but the moment you start
[1047]
introducing properties I feel like
[1050]
it just starts breaking down right uh
[1054]
it just really starts becoming a huge
[1056]
pain in the ass and I just really I just
[1058]
really dislike that you know what I mean
[1059]
uh and then I also on top of that I
[1063]
think rust did it right which is if you
[1065]
define an interface
[1067]
and you have an interface method that
[1069]
you you say you can use you can create a
[1072]
second interface method and actually
[1074]
provide a default implementation which
[1076]
references the first interface method I
[1079]
think that that's a really cool concept
[1081]
where you can actually get some of the
[1083]
benefits of an abstract class
[1084]
thank you baby looking good
[1088]
but it only is abstracted over that
[1091]
individual trait like I think that that
[1093]
is a really really really amazing thing
[1095]
yeah def yeah Dev you didn't know about
[1097]
this oh here check this out okay sorry
[1098]
I'm going to derail this for a quick
[1099]
second just so you guys can see this uh
[1101]
faster than lime if you haven't seen him
[1103]
uh great stuff he has a great blog he
[1106]
has some really good stuff uh the his
[1108]
Advent of code series and I think it's
[1110]
day four I want to say it's day four
[1111]
I've I've
[1113]
yeah here we go um
[1116]
so he builds out this whole trait
[1118]
extension going on right so range
[1120]
contains right contains range and
[1123]
welcome to Costco there you go let's see
[1125]
there you go right here
[1127]
if you define this method you can follow
[1130]
up with contains or is contained open
[1133]
the Costco I love you in which you can
[1136]
actually do this thing right here so I
[1137]
think that this is really fantastic
[1139]
right so you can allow for default
[1141]
implementations if the implementation
[1143]
only uses what is inside the trade
[1146]
itself
[1147]
to me that is like
[1149]
that's like where the big win comes in
[1151]
right
[1153]
this is where the big this is what I
[1155]
used to to harass uh Rich Harrison with
[1158]
I just love this like when I see this it
[1160]
makes me feel really amazing by it like
[1162]
I think that this is the truest best way
[1164]
to have interfaces it is it's it's
[1166]
genuinely the best I I I don't think
[1169]
there's a better way to have them that I
[1171]
can think of currently
[1177]
yeah exactly so that's what makes it so
[1180]
good is that notice that it can't refer
[1182]
to anything that it doesn't know about
[1183]
since contains range must be implemented
[1186]
it can it can use that method because it
[1188]
must be implemented right that is that's
[1191]
radical right like that is radical I
[1195]
love that you know what I mean that is
[1197]
just so sweet
[1200]
yeah how do you uh I just know I just
[1203]
know fast in line he's a good guy
[1204]
yeah it's such a good idea that even
[1206]
Java does it I think Java did it right
[1208]
then Java I mean hey thank you very much
[1210]
I haven't used Java since 1.6 so I don't
[1212]
know what happened since 1.6
[1214]
um I started using groovy two point
[1217]
whatever the hell it was and that was
[1220]
awful I hate groovy
[1227]
let's see how I'm friends what do you
[1228]
think in uh typescript using interface
[1229]
to describe behavior and types of
[1231]
describe the data uh it's just too
[1233]
problematic it's just too problematic
[1235]
typescript interfaces are just naughty I
[1237]
would just in general stay away from
[1239]
them
[1239]
for the most part uh thank you graku
[1242]
welcome for the most part I just stay
[1244]
away from all right so let's see where
[1245]
this is going
[1246]
represents the operations an image file
[1248]
can do load and Save
[1253]
sorry
[1255]
now like before we save a reference to
[1257]
one of our implementations but now
[1260]
through the interface
[1262]
and when the user clicks save on
[1265]
whatever
[1267]
interfaces are a much more lightweight
[1269]
way to do this because our interfaces
[1271]
are minimal
[1274]
I hate the question mark operator like
[1276]
this this I actually dislike this all
[1278]
together
[1280]
it just it makes me feel upset right
[1283]
because it's hiding a problem I I don't
[1285]
I don't my phases are a much more like
[1287]
way to do this because our interfaces
[1289]
are minimal parent classes share
[1291]
everything by default making them more
[1293]
difficult to change
[1295]
but interfaces Define only the critical
[1297]
parts of the contract and are easily
[1299]
tacked onto existing glasses
[1302]
now that we have a nice abstraction for
[1304]
loading and saving files in our app we
[1306]
can actually lift the creation of which
[1307]
image file out of our image app class
[1310]
we'll simply ask the user of the class
[1312]
to pass in the interface instead
[1315]
that way this class can just focus on
[1317]
dealing with the UI commands and the
[1319]
file class can be elsewhere that's much
[1322]
better right this is much much better
[1325]
there's a name for what we just did
[1326]
there dependency injection
[1329]
I'll do a whole video on dependency
[1331]
dependency injection is really hard
[1334]
the problem is dependency injection is
[1337]
great until it's not
[1341]
it's it's it's it's it's something that
[1346]
oh I want to answer this so bad we'll
[1347]
come back to this
[1349]
um it's great until it's not great
[1352]
it's great until it it's not great right
[1354]
when you when you get someone into
[1356]
really intense amounts of it
[1359]
and then default versions of it it's
[1362]
really hard to debug through your code
[1363]
or to even understand where the code's
[1367]
going
[1368]
um
[1369]
like I like dependency injection I think
[1371]
it's a good technique to use I find
[1373]
myself using it less and less uh just
[1376]
because I always find
[1378]
that I end up getting into a place
[1382]
where it hurts like like you have to
[1385]
pull up the doll and you ask me where
[1387]
does it hurt and then I draw a circle
[1388]
around the whole thing you know what I
[1390]
mean
[1391]
it can it can get it can get ouchy
[1395]
di is almost unavoidable exactly there's
[1397]
some levels of di that makes sense
[1399]
there's some levels of di that doesn't
[1401]
make sense like one thing I find that
[1402]
people do with the eyes like say you're
[1403]
building a program to get data from a
[1405]
database
[1406]
and then do something with it now
[1409]
for testability purposes you could go
[1411]
full di on this and do all the la la la
[1413]
or you could do some nice uh you could
[1416]
you could override the Imports and get
[1417]
all this stuff in and inject mock
[1419]
classes and all that crap I hate my
[1420]
classes they're always such a pain in
[1422]
the ass to use
[1423]
um
[1424]
But ultimately in the end I find that
[1426]
most my problems aren't getting data out
[1429]
of a database right like these you start
[1431]
building all these abstractions around
[1432]
it it almost exclusively comes down to
[1434]
me using an interface that I can pass
[1436]
around and just make sure that that
[1438]
thing's correct right like you start you
[1440]
you know like di works until it doesn't
[1442]
work and the moment it starts expanding
[1444]
too much oh man it can just become
[1447]
it just becomes such a nightmare I just
[1448]
I remember being at
[1450]
the tvy code base that Netflix went all
[1453]
in on dependency injection and so
[1455]
everything that you got was like a
[1457]
dependency injected item so everything
[1459]
was like a functor right so everything
[1461]
so you got your you got your you
[1463]
know what I mean like everything was a
[1465]
functor and so like you just
[1467]
like to find out what the hell built
[1469]
your stuff was just impossible to figure
[1471]
out what the hell even built it it was
[1474]
very emotional injection but if you've
[1476]
heard the term before and wondered what
[1477]
it was that's it passing in an interface
[1480]
for what you're going to use
[1484]
I won't say that inheritance is as evil
[1486]
as some would say but I will say that I
[1489]
almost never use it in my code
[1492]
composition isn't perfect you do end up
[1495]
with a lot of boilerplate needing to
[1497]
initialize all of your internal types
[1499]
many implementations will contain the
[1501]
same code repeated
[1503]
and when there's also like a structural
[1505]
problem when it comes to composition I
[1508]
find that sometimes I end up with these
[1510]
like folders where it's just like here's
[1513]
a bunch of functions for playing with
[1515]
events here's a bunch of functions for
[1517]
doing that here's a bunch of functions
[1519]
for doing this other thing and sometimes
[1522]
I hate that you know I mean like
[1524]
sometimes all of a sudden I'm just like
[1525]
I know I have
[1527]
something to pluck the time stamp
[1530]
out of this event
[1533]
but I forget
[1536]
where it went you know what I mean like
[1538]
then I have to go like use references
[1540]
and go find it like it it's not all
[1543]
beautiful it's not all beautiful used
[1544]
code you often need to create a lot of
[1546]
wrapper methods where you simply return
[1548]
a call to an inner type yeah but
[1550]
ultimately composition reduces the
[1552]
surface area between objects which gives
[1555]
you less friction as changes come in
[1558]
inheritance might be useful if you're
[1560]
working inside of an existing system
[1561]
that had highly repetitive code where
[1564]
you only needed to modify one thing
[1566]
for example if you had the need for 100
[1568]
classes to conform to some specific
[1570]
interface which half of them need the
[1573]
same boilerplate over and over again you
[1575]
might say that that means that each
[1576]
class has too much responsibility
[1579]
and you'd be right but changing the
[1580]
plug-in model would cost the team months
[1582]
of work
[1583]
you might not want to put your effort
[1585]
into that just yet
[1586]
if you do use inheritance design the
[1588]
class to be inherited
[1590]
I'd avoid protected variables with
[1592]
direct access like we avoid making our
[1595]
variables public
[1596]
you know every time I've
[1599]
done anything with protected stuff I
[1601]
always find that it's just not the way I
[1603]
wanted it to be
[1605]
you know the more you can separate out
[1609]
the
[1610]
implementation
[1612]
from each level the cleaner it really is
[1614]
for overriding create an explicit
[1616]
protected API that you're supposed to
[1618]
override and access
[1620]
Mark everything else as private final or
[1622]
sealed
[1623]
this prevents bugs when changing your
[1625]
parent classes you notice he said those
[1626]
orders backwards this is because of not
[1629]
understanding what your child's classes
[1631]
have done
[1633]
[Music]
[1635]
that was great
[1636]
I really like code Aesthetics if you if
[1638]
you don't know code Aesthetics you
[1640]
should
[1640]
go subscribe to code Aesthetics he's a
[1642]
really good job I think he does a really
[1645]
really good job with the stuff I pretty
[1647]
much agreed with everything he had to
[1648]
say other than that that no squeal one
[1650]
that he just tossed out right in the
[1652]
middle yeah this is why uh we use no
[1654]
squealed document stores and I'm just
[1656]
like wow
[1660]
calm down calm down
[1663]
I love you this is good though
[1668]
I don't have a strong opinion on
[1669]
inversion of control I'd have to I
[1673]
just like everything it's useful when
[1675]
it's useful it sucks when it sucks I'm
[1677]
not convinced
[1678]
I don't like no squeal it just depends
[1681]
like there's some things that I don't
[1682]
like no squeal for you know what I mean
[1685]
yeah but it only has like seven videos
[1687]
so far uh how was he noticed uh this
[1690]
quickly I it's just that's why that's
[1693]
the thing is that when it comes to
[1694]
YouTube and it comes to the algorithm it
[1696]
comes to everything it's all about the
[1698]
fact
[1699]
like does somebody watch your stuff
[1702]
engage with it and enjoy it and they
[1704]
have their own metrics to determine that
[1706]
and they also have limited screens uh
[1708]
real estate
[1710]
hey guys uh they they also have just
[1712]
limited screen real estate and they can
[1714]
only promote so many videos at once so
[1715]
when they do that they have to make sure
[1717]
that if I'm gonna show this this square
[1719]
has a seven percent chance of getting
[1721]
clicked but only a one minute watch time
[1724]
well that sucks because that's seven
[1725]
percent times one minute right so that's
[1728]
like very little seconds watched oh this
[1730]
one only has a five percent but they're
[1732]
watching all 10 minutes boom like that
[1735]
one's a way better one to put in this
[1736]
position and then not only that you also
[1738]
then have to start doing like this
[1740]
person watches videos that is like this
[1742]
other person you kind of have to think
[1743]
about it