Home Blog Page 9

The Best Tools for Finding New Music and Movies

0

What’s possible in a week? If you dedicated seven days to the achievement of one goal, how ambitious could you make this goal? These were the questions that the multilingual friends Katy and Sara posed themselves when they determined to learn English in one week, to prove that it can be done and anyone can do it with the right methods.

They would attempt to liberate themselves from the distractions and responsibilities of modern-day life in order to cram eight hours of study time and I was observing some of the world’s most capable language learners at work.

The language learning expert: Sara

The friends set themselves the challenge of learning a language in a week in order to stretch themselves, and then it was a question of choosing which language to learn. English presented itself as a natural option; there are nigh on 300,000 English speakers in Germany’s capital, and the areas are dotted with stores adorned with signs in English.

“Truly understanding one’s environment requires one to first understand English”

The first operational step in the friends learning process was to decorate the entire apartment with sticky notes. This had an almost ceremonial touch to it as the friends delved into dictionaries and proceeded to label everything with its corresponding English name.

Within the space of about an hour it was impossible to carry out any menial task, be it making a coffee or flicking off a light switch, without first being presented with at least three different words related to this action.

Sara learning in the park

The importance of the other twin’s presence became immediately apparent as Katy and Sara delegated responsibilities for rooms to decorate with sticky notes. This simple task was augmented by continuous little tests that they would spring on one another, and the fact that they split up their day slightly differently and studied different topics meant that each twin became a source of knowledge for the other.

The most extraordinary moment came towards the end of the week!

The friends simply switched their everyday conversations to English, asking one another if they wanted tea or coffee, were ready to cook dinner or when they were going to leave the house.

Katy and Sara had numerous micro-challenges throughout the week. On the first day they were visited by a English friend who greeted them in English and complimented them on how quickly they’d picked up their first words and phrases.

They then learned the names of fruits and the numbers from one to a billion so that they could visit the English market (although they refrained from purchasing nine hundred thousand kumquats). Displaying their haul after their first functional exchange in English, they beamed with pride and a palpable sense of accomplishment before marching back home to study further.

Katy playing audio lessons

On our second visit to the brother’s apartment 24 hours into the week, we found them sampling dozens of different kinds of English snacks.

Like kids staring at the backs of cereal packs before heading to school, the nutritional information and various special offers and competitions on the packaging were analysed during snack breaks.

There was no moment of complete removal from the language learning process during the eight hours that the friends had allotted to it.

They were constantly using their existing knowledge to support the ever-growing knowledge of English, this being the root of their success.

“you will likely come across words that share common origins with your native tongue”

The friends spent a lot of time engrossed in books or on their computers and apps, flicking and swiping their way through exercises eagerly, but at other times they were to be found searching busily for English radio stations and write-ups of English football games on the web.

There is no definitive method to learn a language fluently

All too often, people enter their weekly language class to converse with their teacher, but then barely have any contact with other speakers and that’s not enough.

The old saying that we can solve problems more effectively when we sleep on it may be especially true if the problem we’re trying to solve is learning a new language.

Motivated Katy out to the library

Researchers from two Swiss universities wanted to know if they could enhance the learning of words from a foreign language by exposing people to the words during non-rapid eye movement sleep the deep, dreamless sleep period that most of us experience during the first few hours of the night.

To find out, they gathered two groups of study participants, all of whom were native German speakers, and gave them a series of Dutch-to-German word pairs to learn at 10 pm. One group was then instructed to get some sleep, while the other group was kept awake.For the next few hours both groups listened to an audio playback of the word pairs they’d already been exposed to and some they hadn’t yet heard.

The researchers then re-gathered both groups at 2 am and gave them a test of the Dutch words to uncover any differences in learning. And indeed there was a difference:

“The group that listened to the words during sleep did better at recalling the words they’d heard”

The simple yet potent trick the researchers employed is known as verbal cueing, and this isn’t the first claim made for its success while sleeping. But what makes this study different is that it puts a finer point on the conditions necessary for this trick to actually work namely, it only works when we’ve already been exposed to the verbal cues before we sleep.

The researchers added a techie dimension by conducting electroencephalographic (EEG)recordings of the sleeping participants brains to track neural electrical activity during the learning period.

They found that learning the foreign words overlapped with the appearance of theta brain waves, an intriguing result since theta is the brain wave state often associated with heightened learning while awake (usually we’re in either the high-frequency, high-alertness alpha or beta states while awake, but it’s thought possible to induce theta state slower in frequency than alpha and beta through concentration techniques).

Mengenal Abstraksi dalam OOP C#

0

A

bstraksi adalah konsep OOP yang menyembunyikan detail rumit dan hanya menampilkan fungsi penting, seperti remote TV yang cukup tekan tombol tanpa tahu cara kerjanya di dalam. Ini membuat kode lebih sederhana dan aman untuk pemula.

Bayangkan smartphone: Kamu cukup tekan ikon kamera untuk foto, tanpa perlu paham sensor atau prosesornya – itu abstraksi dalam kehidupan nyata.

Apa Itu Abstraksi?

Abstraksi fokus pada “apa” yang dilakukan, bukan “bagaimana”. Di C#, dicapai lewat abstract class (kelas tak lengkap, harus diwarisi) dan interface (kontrak method tanpa implementasi). Ini mencegah penggunaan kelas secara langsung dan paksa turunan isi detailnya.

  • Abstract Class: Punya method abstrak (hanya deklarasi) + method biasa.
  • Interface: Hanya method/properti tanpa body (sebelum C# 8, kini bisa default).

Analogi: Resep masak abstrak bilang “panggang 180°C”, turunan tambah “30 menit untuk kue”.

Abstract Class: Kerangka Dasar

Abstract class dideklarasikan abstract, tak bisa diinstansiasi langsung. Method abstrak wajib di-override di kelas turunan.

Contoh Sederhana (Bentuk):

abstract class Bentuk {
    public abstract double Luas();  // Harus diimplementasi turunan
    public void Info() {  // Method biasa
        Console.WriteLine("Ini bentuk geometri.");
    }
}

class Lingkaran : Bentuk {
    private double radius;
    public Lingkaran(double r) { radius = r; }
    public override double Luas() {
        return 3.14 * radius * radius;
    }
}

class Program {
    static void Main() {
        // Bentuk b = new Bentuk();  // ERROR! Abstract
        Lingkaran l = new Lingkaran(5);
        l.Info();
        Console.WriteLine("Luas: " + l.Luas());  // Output: 78.5
    }
}

Ini seperti blueprint rumah: Tak bisa tinggal di blueprint, harus bangun rumah nyata.

Interface: Kontrak Ketat

Interface semua member abstrak secara default (interface), implementasi di kelas yang implement. Satu kelas bisa punya banyak interface.

Contoh (Kendaraan Bermotor):

interface IBermotor {
    void NyalakanMesin();
    void MatikanMesin();
}

interface IEkonomi {
    double HitungBbm();
}

class Motor : IBermotor, IEkonomi {
    public void NyalakanMesin() {
        Console.WriteLine("Mesin motor menyala!");
    }
    public void MatikanMesin() {
        Console.WriteLine("Mesin mati.");
    }
    public double HitungBbm() {
        return 50.5;  // Liter per 100km
    }
}

class Program {
    static void Main() {
        Motor m = new Motor();
        m.NyalakanMesin();
        Console.WriteLine("BBM: " + m.HitungBbm());
    }
}

Analogi: Interface seperti SIM A (motor) + SIM B (mobil) – kendaraan harus patuhi aturan masing-masing.

Perbandingan Abstract Class vs Interface

Aspek Abstract Class Interface
Inheritance Satu saja (:) Banyak (, koma)
Method Biasa Bisa punya Hanya default/static (C# 8+)
Field Bisa Tidak
Kapan Pakai Kerangka umum + shared code Kontrak perilaku spesifik

Pilih abstract untuk “is-a” (Motor is-a Kendaraan), interface untuk “can-do” (Motor can-do Bermotor).

Studi Kasus Latihan untuk SMK

  1. Bangun Perpustakaan: Buat abstract class Buku dengan abstract string Judul() dan virtual void Pinjam(). Turunan: BukuFiksi, BukuNonFiksi. Test di Main, coba instansiasi Buku – error?
  2. Game Sederhana: Interface IAttack (void Serang()), IDefend (void Bertahan()). Class Prajurit : IAttack, IDefend. Implementasi unik, seperti “Pukul pedang” dan “Angkat perisai”. Jalankan simulasi pertarungan.
  3. Toko Online: Abstract Produk dengan abstract double Harga(). Interface IDiskon (double BeriDiskon(10)). Class Laptop : Produk, IDiskon. Hitung harga diskon di Main.
  4. Kendaraan Umum: Interface IJalan (void Jalan()), abstract Kendaraan (abstract int Roda()). Class Bus : Kendaraan, IJalan. Bandingkan dengan Sepeda hanya IJalan.
  5. Mini Project: Sistem Sekolah dengan abstract Siswa (abstract void Belajar()), interface IKelas (void PindahKelas()). Buat SiswaReguler, SiswaKelasKhusus. Tambah polymorphic array Siswa[] dan loop Belajar().

Coba compile di Visual Studio Community (gratis untuk pelajar). Error adalah guru terbaik – debug dan pahami kenapa! Gunakan override tepat untuk method abstrak.

Memahami Properties dalam C#

0

Pada pemrograman berorientasi objek (OOP) di C#, kita sering bekerja dengan kelas dan objek. Salah satu fitur penting dalam kelas adalah properties. Di artikel ini kita akan belajar:

  • Apa itu properties
  • Kenapa properties penting
  • Cara membuat dan menggunakan properties
  • Studi kasus yang implementatif

Semua penjelasan dibuat supaya mudah dipahami teman-teman yang sedang memulai belajar OOP di C#.

Apa Itu Properties di C#?

Dalam C#, properties adalah cara untuk mengakses nilai dari field privat dalam kelas secara terkontrol. Properties terlihat seperti variabel biasa, tapi sebenarnya ada accessor berupa kode get dan set yang mengatur bagaimana nilai dibaca dan ditulis.

Sebagai gambaran:

  • get → mengambil (membaca) nilai
  • set → memberikan (menulis) nilai
    Properties membantu menjaga enkapsulasi — yaitu prinsip OOP untuk melindungi data dari akses langsung yang tidak aman.
private int age;

public int Age
{
    get { return age; }
    set { age = value; }
}

Contoh di atas menunjukkan property Age yang bisa membaca dan mengubah field privat age.

Kenapa Kita Butuh Properties?

Tanpa properties, kita bisa membuat field kelas public dan mengaksesnya langsung. Tapi ini bisa berbahaya karena:

  • Tidak ada aturan untuk validasi nilai
  • Tidak bisa mencegah perubahan nilai yang tidak wajar
  • Kode jadi kurang aman dan sulit dipelihara

Properties hadir untuk memberikan kontrol penuh sambil tetap membuat akses ke data terasa simpel.

Contoh 1: Properties Dasar — Kontrol Data

Misalnya kita punya kelas Mahasiswa dengan nilai skor ujian. Kita ingin skor hanya diisi antara 0 dan 100. Kita buat property yang memeriksa nilai sebelum disimpan:

using System;

class Mahasiswa
{
    private int skorUjian;

    public int SkorUjian
    {
        get { return skorUjian; }
        set
        {
           if (value >= 0 && value <= 100)
                skorUjian = value;
            else
                Console.WriteLine("Nilai harus antara 0 dan 100!");
        }
    }
}


class Program
{
    static void Main()
    {
        Mahasiswa mhs = new Mahasiswa();
        mhs.SkorUjian = 90;
        Console.WriteLine("Skor Ujian: " + mhs.SkorUjian);
        mhs.SkorUjian = 150; // Gagal karena tidak sesuai aturan
    }
}

Di sini property SkorUjian bertindak seperti pengaman:

  • Nilai ditetapkan hanya jika sesuai aturan
  • Bila tidak, muncul pesan peringatan
    Ini contoh bagaimana properties membantu melindungi data tanpa mengorbankan kemudahan penggunaan.

Jenis-Jenis Properties

  1. Read-Write Property – punya get dan set. Bisa dibaca dan diubah.
  2. Read-Only Property – hanya punya get. Cocok untuk data yang harus tetap setelah dibuat.
  3. Write-Only Property – hanya punya set. Jarang dipakai, tapi berguna saat hanya perlu input.
  4. Auto-Implemented Property – property simpel tanpa logika tambahan. C# membuat field tersembunyi otomatis.

Contoh auto-implemented property:

public class Buku

{
    public string Judul { get; set; } = "Belajar C#";
}

Tanpa menulis field privat, C# otomatis menyiapkan bagian internalnya.

Contoh 2: Read-Only Property

Kadang ada data yang hanya boleh dibaca, misalnya ID mahasiswa yang diberi saat objek dibuat:

class Mahasiswa

{
    private readonly int id;
    public int ID
    {
        get { return id; }
    }

    public Mahasiswa(int id)
   {
        this.id = id;
    }
}

ID hanya punya get, sehingga nilainya tidak bisa diubah setelah objek dibuat. Ini membantu menjaga integritas data.

Studi Kasus: Properti Sederhana untuk Toko

Bayangkan aplikasi toko yang punya kelas Produk. Kita ingin:

  • Nama produk disimpan
  • Harga tidak boleh negatif

Ini contoh yang menggunakan properties untuk itu:

using System;

class Produk
{
    private string nama;
    private decimal harga;

    public string Nama
    {
        get { return nama; }
        set { nama = value; }
    }

    public decimal Harga
    {
       get { return harga; }
        set
        {
            if (value >= 0)
                harga = value;
            else
                Console.WriteLine("Harga tidak boleh negatif!");
        }
    }
}


class Program
{
    static void Main()
    {
        Produk barang = new Produk();
        barang.Nama = "Sepatu";
        barang.Harga = 250000; // Benar
        barang.Harga = -10;    // Tidak diterima

        Console.WriteLine($"Produk: {barang.Nama}, Harga: {barang.Harga}");
    }

}

Dengan properties, aturan bisnis seperti “harga tidak boleh negatif” bisa ditanam langsung dalam kelas sehingga tidak perlu dicek di luar program. Ini membuat kode lebih aman dan bersih.

Kesimpulan

Properties adalah fitur penting di C# untuk:

  • Mengontrol akses terhadap field privat kelas
  • Menyediakan fitur baca/tulis/data validasi dalam bentuk yang bersih
  • Membantu menerapkan prinsip enkapsulasi dalam OOP

Properties itu seperti “variabel pintar”: terlihat sederhana saat dipakai, tetapi punya aturan di balik layar. Ini menjadikannya alat yang sangat berguna saat membangun aplikasi yang kuat dan mudah dirawat di C#.

- Advertisement -

Recent Posts