{"id":32583,"date":"2024-11-01T09:10:08","date_gmt":"2024-11-01T09:10:08","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32583"},"modified":"2024-11-01T11:54:43","modified_gmt":"2024-11-01T11:54:43","slug":"flutter-course-5-1-objects-classes-instances","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32583\/","title":{"rendered":"Flutter Course: 5.1 Objects, Classes, Instances"},"content":{"rendered":"<p><body><\/p>\n<p>Flutter is an open-source UI software development kit (SDK) developed by Google, designed to help users easily create modern, high-performance applications. In this course, we will delve deeply into the fundamental concepts of Object-Oriented Programming (OOP), including <strong>class<\/strong>, <strong>object<\/strong>, and <strong>instance<\/strong>. These concepts are essential for structuring and managing Flutter applications.<\/p>\n<h2>1. What is Object-Oriented Programming?<\/h2>\n<p>Object-Oriented Programming (OOP) is one of the programming paradigms that manages data by grouping it as <strong>objects<\/strong>. An object includes <strong>state<\/strong> and <strong>behavior<\/strong>, and defining these objects is precisely what a <strong>class<\/strong> does. The main features of OOP are as follows:<\/p>\n<ul>\n<li>Encapsulation: Bundles the object&#8217;s properties and methods to provide insulation from outside.<\/li>\n<li>Inheritance: Promotes code reuse by defining new classes based on existing classes.<\/li>\n<li>Polymorphism: Defines interfaces that allow different classes to behave in the same way.<\/li>\n<li>Abstraction: Simplifies complex systems efficiently to make them easier to handle.<\/li>\n<\/ul>\n<p>Now, let&#8217;s look at how these OOP concepts are utilized in Flutter.<\/p>\n<h2>2. Class<\/h2>\n<p>A class is a template for creating objects. A class can define data variables and may include methods that manipulate that data. Here is how to define a class in Flutter:<\/p>\n<pre><code>class Car {\n    String color;\n    String model;\n\n    Car(this.color, this.model);\n\n    void display() {\n        print('Car Model: $model, Color: $color');\n    }\n}<\/code><\/pre>\n<p>In the example above, we defined a class called <code>Car<\/code>. This class has two properties, <code>color<\/code> and <code>model<\/code>, which are initialized through the constructor. The <code>display<\/code> method prints the car&#8217;s information. Next, let&#8217;s create objects using this class.<\/p>\n<h2>3. Object and Instance<\/h2>\n<p>An object refers to an instance of a class. In other words, it refers to a real set of data created from a class. You can create multiple objects, each having unique states. For example, we can create instances of the <code>Car<\/code> class as follows:<\/p>\n<pre><code>void main() {\n    Car car1 = Car('red', 'sports car');\n    Car car2 = Car('blue', 'sedan');\n\n    car1.display(); \/\/ Output: Car Model: sports car, Color: red\n    car2.display(); \/\/ Output: Car Model: sedan, Color: blue\n}<\/code><\/pre>\n<p>In the above code, we created two <code>Car<\/code> objects named <code>car1<\/code> and <code>car2<\/code>. Each object stores the color and model information provided at creation, and we can output each car&#8217;s information by calling the <code>display<\/code> method.<\/p>\n<h2>4. Various Components of a Class<\/h2>\n<p>A class can include various components. These include constructors, methods, fields, and access modifiers. Let&#8217;s take a detailed look.<\/p>\n<h3>4.1 Constructor<\/h3>\n<p>A constructor is called when an object is created and is responsible for initializing the object. Dart (the programming language for Flutter) supports named constructors in addition to the default constructor:<\/p>\n<pre><code>class Person {\n    String name;\n    int age;\n\n    Person(this.name, this.age); \/\/ Default constructor\n\n    Person.named(this.name, this.age); \/\/ Named constructor\n}<\/code><\/pre>\n<p>The named constructor provides different ways to initialize, for example, it can be used like <code>Person.named('John Doe', 30)<\/code>.<\/p>\n<h3>4.2 Method<\/h3>\n<p>A method is a function defined within a class. It defines the behavior the object will perform. Methods can change the state of the class or perform operations:<\/p>\n<pre><code>class Animal {\n    String name;\n\n    Animal(this.name);\n\n    void speak() {\n        print('$name is making a sound.');\n    }\n}<\/code><\/pre>\n<h3>4.3 Field<\/h3>\n<p>A field refers to the data variable that belongs to a class. It is used to maintain the state of the object. Fields can be categorized into instance variables and static variables:<\/p>\n<pre><code>class Circle {\n    static const double pi = 3.14; \/\/ Static variable\n    double radius; \/\/ Instance variable\n\n    Circle(this.radius);\n}<\/code><\/pre>\n<h3>4.4 Access Modifier<\/h3>\n<p>Dart allows setting access restrictions on a class&#8217;s fields and methods using various access modifiers, primarily the concepts of <code>public<\/code> and <code>private<\/code>. For example, prefixing a field with <code>_<\/code> makes it private:<\/p>\n<pre><code>class BankAccount {\n    double _balance; \/\/ Private variable\n\n    BankAccount(this._balance);\n\n    void deposit(double amount) {\n        _balance += amount;\n    }\n\n    double get balance =&gt; _balance; \/\/ Public method\n}<\/code><\/pre>\n<h2>5. Class Inheritance<\/h2>\n<p>Inheritance is the ability to create new classes based on existing ones. This makes code reuse and structural hierarchy easier. Here\u2019s an example of class inheritance:<\/p>\n<pre><code>class Vehicle {\n    void start() {\n        print('Vehicle started');\n    }\n}\n\nclass Bike extends Vehicle {\n    void ringBell() {\n        print('Bicycle bell sound!');\n    }\n}<\/code><\/pre>\n<p>In the above example, the <code>Bike<\/code> class extends the <code>Vehicle<\/code> class, meaning it can use the method <code>start<\/code> from the <code>Vehicle<\/code> class:<\/p>\n<pre><code>void main() {\n    Bike bike = Bike();\n    bike.start(); \/\/ Output: Vehicle started\n    bike.ringBell(); \/\/ Output: Bicycle bell sound!\n}<\/code><\/pre>\n<h2>6. Polymorphism<\/h2>\n<p>Polymorphism refers to the ability of objects of different classes to invoke the same method. This enhances the flexibility and reusability of the code. For example:<\/p>\n<pre><code>class Shape {\n    void draw() {\n        print('Drawing a shape.');\n    }\n}\n\nclass Circle extends Shape {\n    @override\n    void draw() {\n        print('Drawing a circle.');\n    }\n}\n\nclass Square extends Shape {\n    @override\n    void draw() {\n        print('Drawing a square.');\n    }\n}<\/code><\/pre>\n<p>Here, various shapes like circles and squares inherit the <code>Shape<\/code> class and override the <code>draw<\/code> method to display appropriate results for each shape.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this course, we have examined the concepts of classes, objects, and instances in Flutter in detail. Object-Oriented Programming is an important concept that serves as the foundation for app development, making it very useful for understanding and designing the structure of Flutter applications. In future courses, we will continue to explore how to write practical applications using these object-oriented concepts.<\/p>\n<p>I hope this article is helpful for your Flutter learning journey!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flutter is an open-source UI software development kit (SDK) developed by Google, designed to help users easily create modern, high-performance applications. In this course, we will delve deeply into the fundamental concepts of Object-Oriented Programming (OOP), including class, object, and instance. These concepts are essential for structuring and managing Flutter applications. 1. What is Object-Oriented &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32583\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Flutter Course: 5.1 Objects, Classes, Instances&#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-32583","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.1 Objects, Classes, Instances - \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\/32583\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flutter Course: 5.1 Objects, Classes, Instances - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Flutter is an open-source UI software development kit (SDK) developed by Google, designed to help users easily create modern, high-performance applications. In this course, we will delve deeply into the fundamental concepts of Object-Oriented Programming (OOP), including class, object, and instance. These concepts are essential for structuring and managing Flutter applications. 1. What is Object-Oriented &hellip; \ub354 \ubcf4\uae30 &quot;Flutter Course: 5.1 Objects, Classes, Instances&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32583\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:10:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:54:43+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Flutter Course: 5.1 Objects, Classes, Instances\",\"datePublished\":\"2024-11-01T09:10:08+00:00\",\"dateModified\":\"2024-11-01T11:54:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/\"},\"wordCount\":645,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Flutter course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32583\/\",\"name\":\"Flutter Course: 5.1 Objects, Classes, Instances - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:10:08+00:00\",\"dateModified\":\"2024-11-01T11:54:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32583\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32583\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flutter Course: 5.1 Objects, Classes, Instances\"}]},{\"@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.1 Objects, Classes, Instances - \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\/32583\/","og_locale":"ko_KR","og_type":"article","og_title":"Flutter Course: 5.1 Objects, Classes, Instances - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Flutter is an open-source UI software development kit (SDK) developed by Google, designed to help users easily create modern, high-performance applications. In this course, we will delve deeply into the fundamental concepts of Object-Oriented Programming (OOP), including class, object, and instance. These concepts are essential for structuring and managing Flutter applications. 1. What is Object-Oriented &hellip; \ub354 \ubcf4\uae30 \"Flutter Course: 5.1 Objects, Classes, Instances\"","og_url":"https:\/\/atmokpo.com\/w\/32583\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:10:08+00:00","article_modified_time":"2024-11-01T11:54:43+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32583\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32583\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Flutter Course: 5.1 Objects, Classes, Instances","datePublished":"2024-11-01T09:10:08+00:00","dateModified":"2024-11-01T11:54:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32583\/"},"wordCount":645,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Flutter course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32583\/","url":"https:\/\/atmokpo.com\/w\/32583\/","name":"Flutter Course: 5.1 Objects, Classes, Instances - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:10:08+00:00","dateModified":"2024-11-01T11:54:43+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32583\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32583\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32583\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Flutter Course: 5.1 Objects, Classes, Instances"}]},{"@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\/32583","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=32583"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32583\/revisions"}],"predecessor-version":[{"id":32584,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32583\/revisions\/32584"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}