The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
Stop Building Ugly APIs: Use the Fluent Interface Pattern
자막 (410 세그먼트)
Let me show you two ways to describe the
same animation. So here's the first
version. So this animation consists of a
number of steps. We rotate, we move, we
scale, we fade, we move again, and we
fade again. And then there's durations
for each of these steps. Second version
looks like this. So it's the same
behavior, but it has a completely
different feel. And the second one is
using a pattern called fluid interface.
In this video, we're going to start with
a small animation engine and make it
cleaner step by step and refactor it
into a fluent API that feels like you're
telling a story in Python. Now, if you
want to learn more about how to design a
piece of software from scratch, I have a
free guide for you. You can get this at
iron./design guide. This contains seven
steps I take when I design new software.
Hopefully, it helps you avoid some of
the mistakes I made in the past.
Iron/design guide. The link is also in
the video description. Now, what is a
fluid interface? A fluid interface is a
style where methods return self. So, you
can chain them. For example, in Python,
that means you could type something like
this,
etc., etc., etc. Now, of course, it's
not a valid code. I'm simply typing it
here, but that's the idea. And the main
goal for this type of interface is that
it's more readable and that it's more
like a flow. So it's not really about
performance or having a clever design or
something like that. You typically use
this interface to write code that
describes a sequence of things to do in
an order that they should happen. And
even if you've never heard of the name
fluid interface, this is probably a
pattern that you've seen before. If you
use pandas for example, uh it uses the
fluent interface on data frames or in
OMS like SQL alchemy, you use it to
construct SQL queries. And finally,
pipeline tools are also a really good
candidate for fluid interfaces. And
these APIs, they feel comfortable
because they match how we think about
transformations. And that's why I picked
animation as a domain to show you how
this pattern actually works. So the way
I set this up is that this is a simple
example application that animates shapes
on a TK inter canvas. So this is my main
file. So the first step is some basic TK
setup like creating a canvas. Uh then I
create a graphics render. That's
something that I built myself. I include
in the code example. Then I define an
animation for a square.
I create a shape of that square where I
pass the animation. So animations are
stored alongside shapes. I do the same
thing for a triangle. So it has some
steps and durations. I then create the
shape of the triangle. Uh then I have
these two shapes. And then whenever I
click a button or touch a key, it will
start the animation by playing a
particular scene. So that gets the
renderer and these shapes. When I run
the script, it shows the canvas. And I
can click on this and then we have these
two animated shapes that I just created.
So like I said, I already created a
simple graphics engine and animation
system for this. The graphic engine is
very basic. It has a convos and it has a
전체 자막은 비디오 플레이어에서 이용 가능
댓글 (0)
로그인하여 댓글 달기인터랙티브 모드
퀴즈
정답:
퀴즈
정답:
영상을 보면서 퀴즈가 나타납니다
암기 팁
이 영상에서
무료로 언어 학습