1
00:00:05,520 --> 00:00:10,100
so once again with now got a working
program but it is now time to remove

2
00:00:10,100 --> 00:00:14,900
those circular references that we've
talked about previously now there is no

3
00:00:14,900 --> 00:00:19,300
need for the song class to store an
artist object anymore we now have a way

4
00:00:19,300 --> 00:00:24,590
to find an artist in the list if we know the
artist's name and that's using the find_

5
00:00:24,590 --> 00:00:30,410
object function which you've seen as using the
code and in addition theirs no need for the

6
00:00:30,410 --> 00:00:34,280
album class to store the artist object
once again the name is all that we need

7
00:00:34,280 --> 00:00:35,740
to be able to

8
00:00:35,740 --> 00:00:40,360
reference that again using the find_object function so it makes

9
00:00:40,360 --> 00:00:44,880
things a lot easier and the class diagram
is now much simplified and I just want to bring

10
00:00:44,880 --> 00:00:50,330
that up on screen you can see there that we can
simply this a lot with it is

11
00:00:50,330 --> 00:00:53,070
simplified by removing that

12
00:00:53,070 --> 00:00:57,020
relationship so once we do that we'll
end up with something like this

13
00:00:57,020 --> 00:01:01,470
the top diagram as you can see there so
that's what we're trying to achieve so

14
00:01:01,470 --> 00:01:06,710
how do we go about doing that and removing the
circular references

15
00:01:06,710 --> 00:01:11,380
well thats the challenge this is the challenge that I'm gonna set you to actually fix in this

16
00:01:11,380 --> 00:01:19,660
video so let me just paste in the text for the challenge so you know what is exactly needs to be done ok so here is what we

17
00:01:19,660 --> 00:01:24,450
want to do we want to modify the program so
that the class structure matches the

18
00:01:24,450 --> 00:01:30,600
simplified diagram now artist objects can
hold references to album objects and album

19
00:01:30,600 --> 00:01:34,450
objects can hold references to song
objects but the key here is there must

20
00:01:34,450 --> 00:01:38,380
be no circular references so that is really
what you're trying to achieve here is to

21
00:01:38,380 --> 00:01:43,340
remove that or set up so their aren't circular references so its now time to do that

22
00:01:43,340 --> 00:01:46,780
so pause the video and go away and see if you can complete that challenge when you

23
00:01:46,780 --> 00:01:49,770
ready to come back and check our
solution start the video again and I'll

24
00:01:49,770 --> 00:01:52,770
go through and show you how to do that

25
00:01:55,250 --> 00:02:00,900
ok so hopefully you managed to solve it so let's go
through and see if we can get this working

26
00:02:00,900 --> 00:02:06,610
so I'm just going to undo these
changes and removed this from the doc

27
00:02:06,610 --> 00:02:14,550
strings because we don't need it their so what need to do well the first change is in the song class and what we gonna do is first change

28
00:02:14,550 --> 00:02:18,560
the doc string to reflect the fact that
the song subject is now going to store the

29
00:02:18,560 --> 00:02:22,840
name of the artists rather
than a reference to the artist object so

30
00:02:22,840 --> 00:02:27,370
come up to the class song which is on
the screen at the moment

31
00:02:27,370 --> 00:02:33,150
we got artist which is an artist we are going to change
it because it is going to be a string now and it's

32
00:02:33,150 --> 00:02:40,620
going to be the name of the songs
creator....

33
00:02:40,620 --> 00:02:45,650
and we don't need to make any other
changes its pretty straightforward

34
00:02:45,650 --> 00:02:49,900
that's really all we need to do with the
song class but of course when we create

35
00:02:49,900 --> 00:02:53,100
new song objects were gonna be passing
the artists name as a string to the init

36
00:02:53,100 --> 00:02:57,080
method instead of passing the artist
object and we are doing this to remove

37
00:02:57,080 --> 00:03:01,390
circular references so the next step is
to go ahead and do that to remove the

38
00:03:01,390 --> 00:03:04,660
circular reference between album and
artist

39
00:03:04,660 --> 00:03:09,970
so go to class album and bring it on the screen
here so artists the artists responsible

40
00:03:09,970 --> 00:03:11,610
for the album if not specified

41
00:03:11,610 --> 00:03:20,830
this is now going to be a string here
that's the name of the artist name of the

42
00:03:20,830 --> 00:03:24,010
artist as supposed to the object responsible for the
album and if not specified

43
00:03:24,580 --> 00:03:27,980
that's all exactly the same as it what it was before

44
00:03:27,980 --> 00:03:35,290
down here on line 39 we got self.artist equals various artist if the parameter

45
00:03:35,290 --> 00:03:38,270
pass or the argument pass was none we are going to
change that

46
00:03:38,270 --> 00:03:42,500
so you no longer going to be trying to create an artist object we are going to be setting that to string

47
00:03:42,500 --> 00:03:47,540
the string of various artists that's
all the change we need here now the

48
00:03:47,540 --> 00:03:51,970
add song method doesn't need to be changed
the reason for that is that it uses

49
00:03:51,970 --> 00:03:56,720
self.artist and then now we are storing
artist as a string that will automatically

50
00:03:56,720 --> 00:04:02,200
be used when creating the songs so finally
we need to change the artists class so

51
00:04:02,200 --> 00:04:06,730
that when it creates a new album it's using
its name rather than passing self

52
00:04:06,730 --> 00:04:10,930
so in that way the artist class will only be
storing the artist name as a string rather

53
00:04:10,930 --> 00:04:15,180
than storing a reference to the artist
object as it is currently doing so

54
00:04:15,180 --> 00:04:17,620
scrolling down to look at the artist class

55
00:04:17,620 --> 00:04:22,710
the change will make the album we

56
00:04:22,710 --> 00:04:26,010
got equals new album name year and self

57
00:04:26,010 --> 00:04:32,880
we no longer want to pass self we want to pass
the attribute self.name so that is

58
00:04:32,880 --> 00:04:36,750
literally the only things that we should
need to change at this point the program

59
00:04:36,750 --> 00:04:41,660
should know run and will tests that shortly
so the artists class stores references

60
00:04:41,660 --> 00:04:46,110
to albums in its list now and the album
class towards references to songs but

61
00:04:46,110 --> 00:04:49,990
they aren't circular references any longer
so neither the song class nor the album

62
00:04:49,990 --> 00:04:53,840
class store artist objects anymore they
just hold the name of the artist as a

63
00:04:53,840 --> 00:04:58,420
string and of course they get looked up with
the find_object function when we

64
00:04:58,420 --> 00:05:02,590
need to find out more information about
that so lets run this and confirm that

65
00:05:02,590 --> 00:05:13,820
it does run...so we will run this and we still get the same
results as we got before so everything is

66
00:05:13,820 --> 00:05:17,660
working nicely with the changes that
we're actually made so that's actually it

67
00:05:17,660 --> 00:05:22,420
that is a basic introduction to
object-oriented programming in Python and

68
00:05:22,420 --> 00:05:28,070
we've seen what classes are now and how to create our own basic classes and

69
00:05:28,070 --> 00:05:33,110
we also look at the concepts of encapsulation and delegation now by taking a program and

70
00:05:33,110 --> 00:05:37,660
changing it to use object oriented
techniques hopefully we've given you an

71
00:05:37,660 --> 00:05:42,060
appreciation of how this alternative
approach can really provide huge benefit

72
00:05:42,060 --> 00:05:47,030
and reliability and also allow you to become
more productive at the same time now we

73
00:05:47,030 --> 00:05:51,310
have really only scratched the surface
of object oriented programming is really

74
00:05:51,310 --> 00:05:55,860
a lot more to cover yet and in Python their is also different implementation options to

75
00:05:55,860 --> 00:05:59,830
consider so I'm going to be covering all that in
the remaining videos in the section so

76
00:05:59,830 --> 00:06:00,850
I'll see you in the next one

