{"id":32589,"date":"2024-11-01T09:10:10","date_gmt":"2024-11-01T09:10:10","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32589"},"modified":"2024-11-01T11:54:41","modified_gmt":"2024-11-01T11:54:41","slug":"flutter-course-5-4-creating-classes","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32589\/","title":{"rendered":"Flutter Course &#8211; 5.4 Creating Classes"},"content":{"rendered":"<p><body><\/p>\n<p>Flutter is a UI toolkit developed by Google, a powerful framework that allows you to create iOS, Android, web, and desktop applications from a single codebase. In this course, we will delve deeply into how to create classes in Flutter. By effectively utilizing classes, you can enhance code reusability and clarify code structure.<\/p>\n<h2>1. Basic Concept of Class<\/h2>\n<p>A class is a core concept of object-oriented programming, allowing us to define objects with specific attributes and functionalities through the framework of a class. The way to create a class in Flutter is similar to other object-oriented languages.<\/p>\n<h3>1.1 Declaring a Class<\/h3>\n<p>To declare a class, the <code>class<\/code> keyword is used. Here is a simple example.<\/p>\n<pre><code>class Animal {\n    String name;\n    \n    Animal(this.name);\n    \n    void speak() {\n        print('$name makes a sound!');\n    }\n}<\/code><\/pre>\n<p>In the example above, we define a class named <code>Animal<\/code>. This class has an attribute called <code>name<\/code> and a method called <code>speak<\/code>.<\/p>\n<h3>1.2 Constructor<\/h3>\n<p>A constructor is a special method that is called when creating an instance of a class. The constructor must have the same name as the class and supports both the default and named constructors.<\/p>\n<pre><code>class Animal {\n    String name;\n    \n    Animal(this.name); \/\/ Default constructor\n\n    Animal.named(this.name); \/\/ Named constructor\n}<\/code><\/pre>\n<h2>2. Class Properties and Methods<\/h2>\n<p>A class defines data and behavior through properties (fields) and methods. Properties are the data that instances of the class possess, while methods define operations that can be applied to this data.<\/p>\n<h3>2.1 Defining Properties<\/h3>\n<p>When defining properties, you can specify data types and set initial values.<\/p>\n<pre><code>class Person {\n    String name;\n    int age;\n\n    Person(this.name, this.age);\n}<\/code><\/pre>\n<p>Here, the <code>Person<\/code> class has two properties: <code>name<\/code> and <code>age<\/code>.<\/p>\n<h3>2.2 Defining Methods<\/h3>\n<p>Methods define the behavior of a class. Methods can take data as input and return results.<\/p>\n<pre><code>class Person {\n    String name;\n    int age;\n\n    Person(this.name, this.age);\n    \n    String introduce() {\n        return 'Hello, my name is $name and I am $age years old.';\n    }\n}<\/code><\/pre>\n<h3>2.3 Getters and Setters<\/h3>\n<p>Getters and setters provide a way to access properties of a class. They are used for data encapsulation and security purposes.<\/p>\n<pre><code>class Person {\n    String _name; \/\/ private field\n\n    Person(this._name);\n    \n    String get name => _name; \/\/ Getter\n    set name(String newName) => _name = newName; \/\/ Setter\n}<\/code><\/pre>\n<h2>3. Class Inheritance<\/h2>\n<p>A class can inherit from another class, which enhances code reusability. Through inheritance, a child class can use the properties and methods of a parent class.<\/p>\n<h3>3.1 Example of Inheritance<\/h3>\n<pre><code>class Animal {\n    void eat() {\n        print('Eating grains.');\n    }\n}\n\nclass Dog extends Animal {\n    void bark() {\n        print('Woof!');\n    }\n}<\/code><\/pre>\n<p>In this example, the <code>Dog<\/code> class inherits from the <code>Animal<\/code> class and can use the <code>eat()<\/code> method.<\/p>\n<h3>3.2 Polymorphism<\/h3>\n<p>Polymorphism is the concept that allows the same interface to be used for different data types. Leveraging polymorphism in Flutter enables handling various forms of objects.<\/p>\n<pre><code>class Cat extends Animal {\n    void bark() {\n        print('Meow!');\n    }\n}\n\nvoid makeSound(Animal animal) {\n    animal.bark();\n}\n\nvoid main() {\n    Dog dog = Dog();\n    Cat cat = Cat();\n    \n    makeSound(dog); \/\/ Woof!\n    makeSound(cat); \/\/ Error occurs\n}<\/code><\/pre>\n<h2>4. Using Mixins<\/h2>\n<p>Mixins allow a class to reuse methods from other classes, enabling code reuse in a way that differs from inheritance.<\/p>\n<pre><code>mixin Flyable {\n    void fly() {\n        print('I am flying!');\n    }\n}\n\nclass Bird with Flyable {\n    void chirp() {\n        print('Chirp!');\n    }\n}<\/code><\/pre>\n<p>In the example above, the <code>Bird<\/code> class uses the <code>Flyable<\/code> mixin to access the <code>fly()<\/code> method.<\/p>\n<h2>5. Summary and Example<\/h2>\n<p>Classes are essential elements of object-oriented programming. Through what we&#8217;ve learned in this course, you will be able to effectively utilize classes in Flutter applications. Here is a simple example that summarizes what we learned.<\/p>\n<pre><code>void main() {\n    Person person = Person('John Doe', 25);\n    print(person.introduce());\n\n    Dog dog = Dog();\n    dog.eat();\n    dog.bark();\n    \n    Cat cat = Cat();\n    cat.eat();\n    cat.bark();\n}<\/code><\/pre>\n<div class=\"note\">When you run this code, you will see the personal introduction, the sound made by the dog while eating, and the sound made by the cat while eating.<\/div>\n<p>In this Flutter course, we thoroughly explored the basic concepts of classes, constructors, methods, inheritance, and mixins. Based on this knowledge, try to build your Flutter applications. You will continue to learn more in the future.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flutter is a UI toolkit developed by Google, a powerful framework that allows you to create iOS, Android, web, and desktop applications from a single codebase. In this course, we will delve deeply into how to create classes in Flutter. By effectively utilizing classes, you can enhance code reusability and clarify code structure. 1. Basic &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32589\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Flutter Course &#8211; 5.4 Creating Classes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[151],"tags":[],"class_list":["post-32589","post","type-post","status-publish","format-standard","hentry","category-flutter-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32589\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Flutter is a UI toolkit developed by Google, a powerful framework that allows you to create iOS, Android, web, and desktop applications from a single codebase. In this course, we will delve deeply into how to create classes in Flutter. By effectively utilizing classes, you can enhance code reusability and clarify code structure. 1. Basic &hellip; \ub354 \ubcf4\uae30 &quot;Flutter Course &#8211; 5.4 Creating Classes&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32589\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:10:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:54:41+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Flutter Course &#8211; 5.4 Creating Classes\",\"datePublished\":\"2024-11-01T09:10:10+00:00\",\"dateModified\":\"2024-11-01T11:54:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/\"},\"wordCount\":480,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Flutter course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32589\/\",\"name\":\"Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:10:10+00:00\",\"dateModified\":\"2024-11-01T11:54:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32589\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32589\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flutter Course &#8211; 5.4 Creating Classes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32589\/","og_locale":"ko_KR","og_type":"article","og_title":"Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Flutter is a UI toolkit developed by Google, a powerful framework that allows you to create iOS, Android, web, and desktop applications from a single codebase. In this course, we will delve deeply into how to create classes in Flutter. By effectively utilizing classes, you can enhance code reusability and clarify code structure. 1. Basic &hellip; \ub354 \ubcf4\uae30 \"Flutter Course &#8211; 5.4 Creating Classes\"","og_url":"https:\/\/atmokpo.com\/w\/32589\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:10:10+00:00","article_modified_time":"2024-11-01T11:54:41+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32589\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32589\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Flutter Course &#8211; 5.4 Creating Classes","datePublished":"2024-11-01T09:10:10+00:00","dateModified":"2024-11-01T11:54:41+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32589\/"},"wordCount":480,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Flutter course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32589\/","url":"https:\/\/atmokpo.com\/w\/32589\/","name":"Flutter Course - 5.4 Creating Classes - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:10:10+00:00","dateModified":"2024-11-01T11:54:41+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32589\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32589\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32589\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Flutter Course &#8211; 5.4 Creating Classes"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32589"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32589\/revisions"}],"predecessor-version":[{"id":32590,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32589\/revisions\/32590"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}