Lecture 2 Introduction to C# - Object Oriented Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.

Slides:



Advertisements
Presentasi serupa
INTRODUCTION TO PSYCHOLOGY. Recommended Literature 1. Introduction to Psychology : Gateway to Mind and Behavior by Dennis Coon and John O. Mitterer 2.
Advertisements

Membuat class sendiri.
Slide 3-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercises Apa saja komponen utama.
Other OOP Basic Viska Mutiawani, M.Sc. Konsep penting Method overloading Encapsulation this keyword final static.
JAVA CLASS Bahasa Pemrogramam BAHASA PEMROGRAMAN PERTEMUAN #9.
Modul 14 – Hendi Hermawan - 1
MEMORY Bhakti Yudho Suprapto,MT. berfungsi untuk memuat program dan juga sebagai tempat untuk menampung hasil proses bersifat volatile yang berarti bahwa.
Praktikum 9 Pemrograman Berbasis Obyek
Dictionary (Icomparable dan IComparer) Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.
Object Oriented Programming
LOGO Manajemen Data Berdasarkan Komputer dengan Sistem Database.
Workshop SCS: Java Game Programming
Lecture 1 Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Linked List dan Double Linked List
BASH – Shell Programming Guide Erick, Joan © Sekolah Tinggi Teknik Surabaya 1.
Operator dan Assignment Pertemuan 3 Pemrograman Berbasis Obyek Oleh Tita Karlita.
Lecture 8 Set and Dictionary Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Web Teknologi I (MKB511C) Minggu 12 Page 1 MINGGU 12 Web Teknologi I (MKB511C) Pokok Bahasan: – Text processing perl-compatible regular expression/PCRE.
OBJECT ORIENTED PROGRAMMING
Lecture 9 Single Linked List Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Pemrograman Berbasis Obyek
MINGGU 5 Java Programming (MKB614C)
OPERATOR OVERLOADING The ability to provide the operators with a special meaning for a data type but its original meaning is not lost. Example: Operator.
Variabel, Method & Constructor Oleh : Nur Hayatin, S.ST Teknik Informatika – UMM 2011.
Class, Inheritance, Encapsulation & Interface
Lecture 2 Object-oriented Programming Concepts Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Pemrograman Berorientasi Obyek Oleh Tita Karlita
Review :: Kisi-kisi UTS ::
Pemrograman Berorientasi Obyek
Class Member Access Control
Dasar Pemrograman Java Pertemuan 2 Pemrograman Berbasis Obyek Oleh Tita Karlita.
Enkapsulasi Pemrograman Berorientasi Obyek Oleh Tita Karlita.
Class and Object Introduction Specifying a Class Defining Member Function A C++ Program with Class Nesting of Member Functions Private Member Functions.
1 Pertemuan 6 Encapsulation Lanjutan Matakuliah: T0044/Pemrograman Berorientasi Obyek Tahun: 2005 Versi: 1.0.
1 Pertemuan 17 Input / Output Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
OOP Java 06 Polymorphism.
Struktur Data List Linear : Linked List (Single Linkedlist)
Dasar Pemrograman Java Pertemuan 2 Pemrograman Berbasis Obyek.
INHERITANCE (Oleh : Nur Hayatin, S.ST)
METHOD, ARRAY DAN STRING
OOP Java Minggu 2b Dasar OOP. Class (1) Deklarasi class : [ *] class { [ *] } Cat : [] = optional, * = repeat 0-N.
1 Pertemuan 5 Encapsulation Matakuliah: T0044/Pemrograman Berorientasi Obyek Tahun: 2005 Versi: 1.0.
Pertemuan 10 Constructor dan Destructor
1 Pertemuan 10 Pemrograman Berorientasi Objek Matakuliah: >/ > Tahun: > Versi: >
Bayu Priyambadha, S.Kom.  Classes, which are the "blueprints" for an object and are the actual code that defines the properties and methods.  Objects,
Binary Search Tree. Sebuah node di Binary Search Tree memiliki path yang unik dari root menurut aturan ordering – Sebuah Node, mempunyai subtree kiri.
Dasar query basis data dengan SQLite
Enkapsulasi.
Inheritance (2).
FONDASI PEMROGRAMAN & STRUKTUR DATA #8
Access Modifier.
Constructor dan Overloading
Dasar Pemrograman Record.
Association, Composition dan Inheritance
Linear Data Structures (Array)
Pemrograman Berorientasi Objek
ADVERTORIAL Pertemuan 15 & 16
Method (Metode).
Membuat Kelas.
Class.
ANDROID ACTIVITY.
Dasar Pemrograman Record.
Object Oriented Programming
HughesNet was founded in 1971 and it is headquartered in Germantown, Maryland. It is a provider of satellite-based communications services. Hughesnet.
Pemrograman berorientasi objek
Sorting using a Lambda Expression
Exploring C-Chem with numeric MM and Ab-Initio methods Masood Malekghassemi – Systems Lab Abstract Computational chemistry is no new subject.
Conditional Move and Arrays
HOW TO IMPROVE YOUR PUBLIC SPEAKING SKILLS. 2 3 INIKAH YANG SERING ANDA ALAMI SAAT PRESENTASI?
FONDASI PEMROGRAMAN & STRUKTUR DATA #7
Transcript presentasi:

Lecture 2 Introduction to C# - Object Oriented Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1

class Mahasiswa { public String NRP {get; set; } public String Nama {get; set; } public int energy {get; set; } public Mahasiswa(){ } public void Kuliah(){ energy--; } Mahasiswa mhs = new Mahasiswa(); 2 © Sekolah Tinggi Teknik Surabaya Constructor Property Method

3 © Sekolah Tinggi Teknik Surabaya » A class defined within another class is called nested. class Container { class Nested { // Add code here. } Container.Nested nestedInstance = new Container.Nested();

class Bangun{ public int Keliling {get; set;} public Bangun(int sisi){ //persegi Keliling=sisi*4; } public Bangun(int panjang, int lebar){ //balok Keliling=2*(panjang+lebar); } public Bangun(int a,int b,int c){ //segitiga Keliling=a+b+c; } 4 © Sekolah Tinggi Teknik Surabaya Same Name, Different Parameter

struct Mahasiswa { public string NRP; public string Nama; public int energy; public Mahasiswa(string a, string b, int c){ NRP = a; Nama = b; energy = c; } Mahasiswa mhs; mhs = new Mahasiswa(); mhs = new Mahasiswa("123", "456", 10); mhs.energy = 96; 5 © Sekolah Tinggi Teknik Surabaya

» Fields cannot be initialized within struct (except const or static ). » Structs can declare constructors that have parameters, but not default constructor (a constructor without parameters) or a destructor. » Structs are value types and classes are reference types. » Unlike classes, structs can be instantiated without using a new operator. 6 © Sekolah Tinggi Teknik Surabaya

» A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from System.ValueType, which inherits from System.Object. » A struct can implement interfaces. » A struct can be used as a nullable type and can be assigned a null value. 7 © Sekolah Tinggi Teknik Surabaya

8 ModifierDescription privatecan be accessed only by code in the same class or struct protected can be accessed only by code in the same class or struct, or in a class that is derived from that class internal can be accessed by any code in the same assembly, but not from another assembly protected internal can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly public can be accessed by any other code in the same assembly or another assembly that references it

» Classes and structs that are declared directly within a namespace is internal if no access modifier is specified » The access level for class members and struct members, including nested classes and structs, is private by default 9 © Sekolah Tinggi Teknik Surabaya

» Struct Instances vs. Class Instances ˃Struct: value type ˃Class: reference type » Object Identity vs. Value Equality ˃ Equals method 10 © Sekolah Tinggi Teknik Surabaya

public struct Person { internal string Name; internal int Age; internal Person(string name, int age) { Name = name; Age = age; } Person p1 = new Person("Him", 25); Person p2 = new Person("Him", 25); if (p1.Equals(p2)) { Console.WriteLine("Equal"); // < } Else { Console.WriteLine("Not Equal"); } Console.ReadKey(); 11 © Sekolah Tinggi Teknik Surabaya

public class _Person { internal string Name { get; set; }; internal int Age { get; set; }; internal _Person(string name, int age) { Name = name; Age = age; } _Person p1 = new _Person("Him", 25); _Person p2 = new _Person("Him", 25); if (p1.Equals(p2)) { Console.WriteLine("Equal"); } Else { Console.WriteLine("Not Equal"); // < } Console.ReadKey(); 12 © Sekolah Tinggi Teknik Surabaya

13 © Sekolah Tinggi Teknik Surabaya

14 © Sekolah Tinggi Teknik Surabaya class Manusia { } class Mahasiswa:Manusia { }

class Manusia { } class Mahasiswa:Manusia { } class Asisten:Manusia { } Manusia m = new Mahasiswa(); m = new Asisten(); 15 © Sekolah Tinggi Teknik Surabaya

» Mark method to be overridden with virtual keyword ˃Can only be placed on methods and properties » Mark method that override base class with override keyword ˃Can only be placed on methods and properties » If you want to hide (ignore) base class method, use new keyword ˃Can be placed on class members 16 © Sekolah Tinggi Teknik Surabaya

public class BaseClass { public virtual void DoWork() { } public virtual int WorkProperty { get { return 0; } } public class DerivedClass : BaseClass { public override void DoWork() { } public override int WorkProperty { get { return 0; } } DerivedClass B = new DerivedClass(); B.DoWork(); // Calls the new method. BaseClass A = (BaseClass)B; A.DoWork(); // Also calls the new method. 17 © Sekolah Tinggi Teknik Surabaya

public class BaseClass { public void DoWork() { WorkField+=10; } public int WorkField; } public class DerivedClass : BaseClass { public new void DoWork() { WorkField+=100; } public new int WorkField; } DerivedClass B = new DerivedClass(); B.DoWork(); // Calls the new method. BaseClass A = (BaseClass)B; A.DoWork(); // Calls the old method. 18 © Sekolah Tinggi Teknik Surabaya

public class A { public virtual void DoWork() { } } public class B : A { public override void DoWork() { } } public class C : B { public sealed override void DoWork() { } } public class D : C { public new void DoWork() { } } 19 © Sekolah Tinggi Teknik Surabaya

» Interface Statement interface ISampleInterface { void doSomething(); } » Class implement interface class SampleClass : ISampleInterface { void doSomething() { // Method implementation. } 20 © Sekolah Tinggi Teknik Surabaya

» Classes, structures, interfaces and methods in the.NET Framework can type parameters that define types of objects that they can store or use. » The most common example of generics is a collection, where you can specify the type of objects to be stored in a collection. 21 © Sekolah Tinggi Teknik Surabaya

» To define a generic class: Public class ClassKu { public T isi; } » To create an instance of a generic class: ClassKu mine = new ClassKu (); mine.isi = "Hello World"; ClassKu mine = new ClassKu (); mine.isi = 123; 22 © Sekolah Tinggi Teknik Surabaya

» Refer to the The Elven Shrine Problem 23 © Sekolah Tinggi Teknik Surabaya

» Andrew Troelsen, Pro C# and The.Net 4.5 Framework (Sixth Edition), Apress, 2012 » Object-Oriented Programming (C# and Visual Basic), us/library/dd aspx, accessed March 16 th, us/library/dd aspx » Classes and Structs (C# Programming Guide), us/library/ms aspx, accessed March 16 th, 2014http://msdn.microsoft.com/en- us/library/ms aspx 24 © Sekolah Tinggi Teknik Surabaya